Reactjs 如何检查用户是否已经使用aws cognito用户池登录到项目中的任何位置?
我正在应用程序中执行SSO(单点登录)。我将AWS cognito用于it,用户池和身份池用于用户 我已经设置了用户池、身份池和使用托管UI 当我使用自定义UI登录并调用下面的cognito函数时:Reactjs 如何检查用户是否已经使用aws cognito用户池登录到项目中的任何位置?,reactjs,meteor,single-sign-on,amazon-cognito,Reactjs,Meteor,Single Sign On,Amazon Cognito,我正在应用程序中执行SSO(单点登录)。我将AWS cognito用于it,用户池和身份池用于用户 我已经设置了用户池、身份池和使用托管UI 当我使用自定义UI登录并调用下面的cognito函数时: cognitoUser.authenticateUser(authenticationDetails, { onSuccess: function (result) { var accessToken = result.getAccessT
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
var accessToken = result.getAccessToken().getJwtToken();
AWS.config.region = config.region;
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId : config.IdentityPoolId, // your identity pool id here
Logins : {
'cognito-idp.<region>.amazonaws.com/<pool-id>': result.getIdToken().getJwtToken()
}
});
//refreshes credentials using AWS.CognitoIdentity.getCredentialsForIdentity()
AWS.config.credentials.refresh((error) => {
console.log("in refresh");
if (error) {
console.error(error);
} else {
console.log('Successfully logged!');
}
});
},
onFailure: function(err) {
console.log("in failure");
alert(err.message || JSON.stringify(err));
},
mfaRequired: function(codeDeliveryDetails) {
// MFA is required to complete user authentication.
// Get the code from user and call
console.log("in mfa required");
cognitoUser.sendMFACode(mfaCode, this)
}
});
我得到空值
是否有任何方法获取当前登录用户,以便我可以确定用户是否登录,并相应地执行下一步操作。而不是
var userPool=new AmazonCognitoIdentity.CognitoUserPool(config.poolData)
使用全局。userPool@Jishnu由于global.userPool不是一个函数,而不是var userPool=new AmazonCognitoIdentity.CognitoUserPool(config.poolData)
use global,所以我收到了一个错误。userPool@Jishnu由于global.userPool不是函数,因此我收到错误消息
var AmazonCognitoIdentity = require('amazon-cognito-identity-js');
var userPool = new AmazonCognitoIdentity.CognitoUserPool(config.poolData);
console.log("cog user: ", userPool.getCurrentUser());