I use AWS Cognito for user pools and authentication.
My registration works, but my login function throws an error:
/node_modules/aws-sdk/lib/request.js:31 throw an error; ^
ReferenceError: window not defined
Here is the function:
app.post('/login', function(req, res, next) { console.log("Email: " + req.body.email); console.log("Password: " + req.body.password); var authenticationData = { Username: req.body.username, Password: req.body.password }; var authenticationDetails = new AWS.CognitoIdentityServiceProvider .AuthenticationDetails(authenticationData); var poolData = { UserPoolId: '*removed for security*', ClientId: '*removed for security*' }; var userPool = new AWS.CognitoIdentityServiceProvider.CognitoUserPool( poolData); var userData = { Username: req.body.username, Pool: userPool }; var cognitoUser = new AWS.CognitoIdentityServiceProvider.CognitoUser( userData); cognitoUser.authenticateUser(authenticationDetails, { onSuccess: function(result) { console.log('access token + ' + result.getAccessToken().getJwtToken()); AWS.config.credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId: '*removed for security*', Logins: { '*removed for security*': result .getIdToken().getJwtToken() } }); }, onSuccess: function(suc) { console.log('Login Successful!'); }, onFailure: function(err) { console.log('Login Unsuccessful'); alert(err); }, }); });
I am sure that the error occurs during the execution of the following line, when I placed debug logs all over the code and was executed only here:
var cognitoUser = new AWS.CognitoIdentityServiceProvider.CognitoUser(userData);
source share