* Which Category is your question related to? *
Auth
* What AWS Services are you utilizing? *
Cognito, AWS AppSync
* Provide additional details e.g. code snippets *
I'd like to know how to save the token generated when a user logs in, this is the code I'm using for this functionality:
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
try {
await Auth.signIn("[email protected]", "MyAwesomePassword");
Router.push("/account");
} catch (error) {
setErrorMessage(error.message);
}
}
So, when the user is redirected to the account route, I fetch the token of this user with the method Auth.currentAuthenticatedUser(); but this one does not exist. This is because the token is not saved... I've been looking for information and I could find this what I want to know is if this example is a good practice to implement it or someone has a better code for this? Thank you!
Two things could be at fault here:
There was a race-condition with Auth.currentAuthenticatedUser() where the token wasn't immediately available after logging in, but has since been fixed.
Please see my synopsis on changes here: https://github.com/aws-amplify/amplify-js/issues/5435#issuecomment-692990722
Please update to @latest and if you're still running into issues, please open an issue using our new issue template, so that I can quickly reproduce it & respond. 馃檹
Yeah, I've been following how SSR will work on Amplify, and it's wonderful!
Awesome! Thanks for your support @MontoyaAndres! 馃槏