0

我使用cognito Amazon Webservice進行用戶管理。AngularJS上的AWS Cognito登錄錯誤

我已經管理簽約到我了userpool但每次我試圖登錄到我的用戶羣我有這個控制檯錯誤:

Error: this.pool.getUserPoolId is not a function 

我不知道哪裏是getUserPoolId ...

編輯:我已經在我的登錄功能,在一個工廠,是我的代碼:

login: function(username, password) { 
     var authenticationData = { 
       Username : username, 
       Password : password 
     }; 
     var userData = { 
       Username :username, 
       Pool : poolData 
     }; 
     var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData); 

     var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData); 
     cognitoUser.authenticateUser(authenticationDetails, { 
     onSuccess: function (result) { 
      console.log('access token + ' + result.getAccessToken().getJwtToken()); 
      /*Use the idToken for Logins Map when Federating User Pools with Cognito Identity or when passing through an Authorization Header to an API Gateway Authorizer*/ 
      console.log('idToken + ' + result.idToken.jwtToken); 
    }, 

    onFailure: function(err) { 
      alert(err); 
    }, 

     }); 
     } 

有誰知道該怎麼辦?

+0

我們需要的代碼來理解這個問題的背景下。 – jonode

+0

Thansk我已編輯我的問題。 – rastafalow

回答

0

的AWS Cognito的JavaScript SDK初始化模式,您需要通過 「數據對象」 到AWS SDK構造。作爲回報,SDK使用各種連接方法爲您提供AWS「界面」。

我認爲從您的代碼中,您使用的是data object而不是後續的interface

實施例:

// Data Object used for initialization of the interface 
const userPoolData = { 
    UserPoolId: identityPoolId, 
    ClientId: clientId 
} 

// The `userPoolInterface`, constructed from your `poolData` object 
const userPoolInterface = new AWSCognito 
    .CognitoIdentityServiceProvider 
    .CognitoUserPool(userPoolData) 

在你提供的代碼,似乎要傳遞的userData對象(用於初始化),在這裏應順便指出應該已經先前初始化的userPool接口。

試試這個:

login: function(username, password) { 

    // 1) Create the poolData object 
    var poolData = { 
     UserPoolId: identityPoolId, 
     ClientId: clientId 
    }; 

    // 2) Initialize the userPool interface 
    var userPool = new AWSCognito 
     .CognitoIdentityServiceProvider 
     .CognitoUserPool(poolData) 

    // 3) Be sure to use `userPool`, not `poolData` 
    var userData = { 
     Username : username, 
     Pool : poolData, // <-- Data?! Oops.. 
     Pool : userPool // "interface", that's better :) 
    }; 

    var authenticationData = { 
     Username : username, 
     Password : password 
    }; 

    var cognitoUser = new AWSCognito 
     .CognitoIdentityServiceProvider 
     .CognitoUser(userData) 

    var authenticationDetails = new AWSCognito 
     .CognitoIdentityServiceProvider 
     .AuthenticationDetails(authenticationData); 

    cognitoUser.authenticateUser(...etc...); 
} 

在線試玩:

如果有幫助,我做筆記和做例子,當我穿行於AWS Cognito SDK中的例子。歡迎您結帳我正在使用的Github回購。如果你可以測試一個有效的例子,它可能會有所幫助。

Github Repository /Live Demo

0

我假設你正在初始化您的poolData對象:

var poolData = { 
    UserPoolId : '...', // Your user pool id here 
    ClientId : '...' // Your client id here 
}; 
+0

當然,我會這樣做 – rastafalow

相關問題