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

相关问题