首页 > 解决方案 > AWS Cognito 错误:没有为未经身份验证的访问提供 Cognito 身份池

问题描述

var normalAuth = async (username, password) => {   
    try{
        var user = await Auth.signIn(username, password)
        console.log(user)
        if(user.challengeName === "NEW_PASSWORD_REQUIRED"){
            console.log("assigning new password!")
            user = await Auth.completeNewPassword(user, "password") // give the user a new password. this would NOT be included in any kind of production code, its only here as a work around
            console.log(user)
        } // work around. users created in the console are only given temporary passwords, and as such have no authorization
        // setting a new password will fix this

        console.log(await Auth.currentCredentials()) // THIS THROWS AN ERROR?!?!
        setAuthState(false) // auth is no longer in progress
    }
    catch(error){
        console.error(error)
    }
}

我正在尝试在身份验证后从我的 Amplify 用户那里获取令牌,但我收到了错误

No Cognito Identity pool provided for unauthenticated access

这很奇怪,因为我根本没有使用身份池。我的基线假设是我根本不需要在我的放大配置中提供身份池 ID。

配置看起来像这样

var amplifyConfig = {
    Auth: {
        mandatorySignIn: false,
        region: "us-east-1",
        userPoolId: "mypoolid",
        userPoolWebClientId: "myclientid"
    }
}

user真正奇怪的部分是,在我进行身份验证后,令牌实际上就在那里。只有当我尝试以这种方式特别检索它们时才会引发错误。

知道这里发生了什么吗?

标签: amazon-web-servicesamazon-cognitoaws-amplify

解决方案


推荐阅读