首页 > 解决方案 > 联合 google 登录问题(aws amplify 和 Vue js)

问题描述

我用 vue js 和 aws amplify cognito 设置了 google auth。首次登录时,我收到此消息

Sign in failure ValidationException: 1 validation error detected: Value '{xxx.amazonaws.com/xxx}' at 'logins' failed to satisfy constraint: Map value must satisfy constraint: [Member must have length less than or equal to 50000, Member must have length greater than or equal to 1]

在第二次登录(按下按钮)时,它登录良好。

为什么不先登录,为什么会收到此消息?

配置:

const awsmobile = {
    "aws_project_region": "ap-south-1",
    "aws_cognito_identity_pool_id": "ap-south-1:25071751-c943-443a-94ab-62c6b0f1c496",
    "aws_cognito_region": "ap-south-1",
    "aws_user_pools_id": "ap-south-1_NAZCqoylw",
    "aws_user_pools_web_client_id": "38a1itpo95f3tgln6vq43u3u4o",
    "oauth": {
        "domain": "mobileweb-dev.auth.ap-south-1.amazoncognito.com",
        "scope": [
            "phone",
            "email",
            "openid",
            "profile",
            "aws.cognito.signin.user.admin"
        ],
        //"redirectSignIn": "https://test-kutumbh-app.netlify.app/home",
       // "redirectSignOut": "https://test-kutumbh-app.netlify.app",
       //"redirectSignIn": "https://dev-kutumbh-app.netlify.app/home",
       //"redirectSignOut": "https://dev-kutumbh-app.netlify.app",
       "redirectSignIn": "http://localhost:3000/home",
       "redirectSignOut": "http://localhost:3000",
        "responseType": "code"
    },
    "federationTarget": "COGNITO_USER_POOLS"
};


export default awsmobile;

enter code here

在此处输入图像描述

标签: amazon-web-servicesvue.jsamazon-cognitoaws-amplify

解决方案


默认情况下,Amplify 将在 Safari/Chrome 中打开 Cognito 托管 UI,但您可以通过提供自定义 URL 打开器来覆盖该行为。

解决使用 InAppBrowser 将给定 URL 转换为所需形式的问题,如Ashish-Nanda 评论在此问题中所建议的。

Amplify.configure({
    ...config, oauth: {
        ...config.oauth,
        urlOpener: async function urlOpener(url, redirectUrl) {
            await InAppBrowser.isAvailable();
            const { type, url: newUrl } = await InAppBrowser.openAuth(url, redirectUrl, {
                showTitle: false,
                enableUrlBarHiding: true,
                enableDefaultShare: false,
                ephemeralWebSession: false,
            });

            const splitUrl = `myapp://?${newUrl.split("#_=_")[0].split("?")[1] || ''}`;
            if (type === 'success') {
                Linking.openURL(splitUrl);
            }
        }

    }
})

推荐阅读