Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where to save token when Log In with Next.js #5097

Closed
MontoyaAndres opened this issue Mar 14, 2020 · 4 comments
Closed

Where to save token when Log In with Next.js #5097

MontoyaAndres opened this issue Mar 14, 2020 · 4 comments
Assignees
Labels
question General question React React related issues SSR Issues related to Server Side Rendering

Comments

@MontoyaAndres
Copy link

** 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("AwesomeEmail@gmail.com", "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!

@MontoyaAndres MontoyaAndres added the question General question label Mar 14, 2020
@ericclemmons ericclemmons added this to the Support SSR (Auth + API) milestone Mar 17, 2020
@ericclemmons ericclemmons added React React related issues SSR Issues related to Server Side Rendering labels Mar 18, 2020
@ericclemmons ericclemmons self-assigned this Apr 24, 2020
@ericclemmons
Copy link
Contributor

Two things could be at fault here:

  1. There was a race-condition with Auth.currentAuthenticatedUser() where the token wasn't immediately available after logging in, but has since been fixed.

  2. feat(SSR): withSSRContext #6146 automatically handles tokens for Next.js sot hey can be passed to the server.

    Please see my synopsis on changes here: Server-Side Rendering (SSR) with Next.js #5435 (comment)

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. 🙏

@MontoyaAndres
Copy link
Author

Yeah, I've been following how SSR will work on Amplify, and it's wonderful!

@ericclemmons
Copy link
Contributor

Awesome! Thanks for your support @MontoyaAndres! 😍

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question General question React React related issues SSR Issues related to Server Side Rendering
Projects
None yet
Development

No branches or pull requests

2 participants