網站搜尋

javascript - ResourceNotFoundException:使用者池 xyz 不存在 - Cognito adminConfirmSignup


不知什麼原因,只有 adminConfirmSignup 會出現使用者池不存在的錯誤。CognitoUser 不會出現該錯誤。請參考以下程式碼:

let cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData)
var cognitoAdmin = new AWS.CognitoIdentityServiceProvider({ region: process.env.COGNITO_POOL_REGION! });
await cognitoAdmin.adminConfirmSignUp(confirmParams, async(err, data) => { //Only this gives the user pool does not exist error
    if (err) {
        console.log(`This is the admin user confirm error ---> ${err}`)
    } else {
        console.log(`Entered else`);
        await cognitoUser.authenticateUser(authenticationDetails, {
            onSuccess: async(result) => {
                cognitoUser.changePassword(resetDetails.currentPassword, resetDetails.newPassword, (err, data) => {
                    if (err) {
                        reject(err);
                    } else {
                        console.log(`This is the success response of cognito change password -----> ${JSON.stringify(data)}`);
                        resolve(data);
                    }
                })
            },
            onFailure: (error) => {
                console.log(`This is the onFailure error ----> ${JSON.stringify(error)}`);
                reject(error);
            }
        })
    }
})

如果我使用 CognitoUser 方法(當我手動確認用戶並且僅使用 cognitoUser 方法進行身份驗證和重設密碼時),密碼重設是有效的。

答案#1

您在 SDK 調用中的參數 UserPoolId 不正確。僅憑您發布的內容無法看到這一點。

答案#2

在呼叫那個函數前需要再加一個 await

await cognitoUser.changePassword(...)

像這樣