从远程后端加载AWS Amplify配置参数

时间:2020-04-20 17:22:47

标签: amazon-web-services aws-amplify aws-serverless

我正在构建一个利用AWS Amplify的React应用。我想加载从API端点传递给Amplify的参数

Amplify.configure({
        Auth: {
            mandatorySignIn: true,
            region: data.region,
            userPoolId: data.user_pool,
            userPoolWebClientId: data.app_client_id,
        },
    });

“数据”是API返回的数据

这是我尝试过的:

getCognitoConfigs()
.then(({ data }) => {
    console.log(data);
    const { location } = window;
    const isLocalhost =
        location.hostname === "localhost" ||
        location.hostname === "127.0.0.1" ||
        location.hostname === "";

    Amplify.configure({
        Auth: {
            mandatorySignIn: true,
            region: data.region,
            userPoolId: data.user_pool,
            userPoolWebClientId: data.app_client_id,
        },
    });
    Auth.configure({
        oauth: {
            //COGNITO DOMAINs

            domain: data.domain,
            scope: [
                "phone",
                "email",
                "profile",
                "openid",
                "aws.cognito.signin.user.admin",
            ],
            responseType: "code",
            redirectSignIn: !isLocalhost
                ? data.callback_urls[0]
                : "https://localhost:3000/",
            redirectSignOut: !isLocalhost
                ? data.logout_urls[0]
                : "https://localhost:3000/",
        },
    });
})
.catch((err) => console.log(err));

我从此导入getCognitoConfigs

const getCognitoConfigs = () => {
return axios.get(`${apiurl.apiurl}/logininfo`);};

似乎Amplify在处理我使用的异步获取方法时遇到了一些问题,并不断返回“ Amplify is not configure not正确配置”。尽管出现错误,我仍然能够使用Amplify提供的大多数功能。但是,有些仅当我直接传递参数时才能使用。任何解决方法?谢谢。

0 个答案:

没有答案