I've been following the Serverless Stack tutorial and can get a positive response with calling Auth.signIn(username, passsword)
The current workflow we have is that the user will need to reset their password as accounts will be handed out.
The .changePassword
function takes 3 arguments; user, oldPassword, newPassword
I can't for the life of me figure out what it's looking for for the user. When I set the object returned from .signIn()
I get the following error:
Local storage is missing an ID Token, Please authenticate
Obviously I wouldn't use this flow for production, but I'm trying to figure out what Auth is looking for.
Auth.signIn(this.state.emailAddress, this.state.password)
.then(user => {
this.setState({ isLoading: false, user });
}).then(async () => {
Auth.changePassword(this.state.user, 'P@ssw0rd!', 'NewP@ssw0rd!');
}).catch(err => {
this.setState({ isLoading: false, errorMessage: err.message })
});
I do see an ID token in the Storage property from the object returned from .signIn
. For clarification: I probably shouldn't have placed it in the chaining. I'm not really doing above in practice. When I save the response from Signin and pass it to the changePassword I get the localstorage error. I'm wondering if there is a config issue setting up Amplify that normally would place this info in localStorage.
Auth.changePassword
takes in aCognitoUser
as it's first argument, something which should be returned fromAuth.signIn
.The issue here, is your promise chaining, and using
this.setState()
and reading it back before it's actually been set:From the React docs:
The easiest way to fix this, is to return the user in the first
.then
callback, to pass it to the second:Personally, I think it would look a lot nicer entirely in async/await: