#✅ - How to tell if user is signed in?

3 messages · Page 1 of 1 (latest)

loud tangle
#

WIth Amplify v6 and Next.js, on a client component, how can you tell if a user is logged in without throwing an error? getCurrentUser throws an error, do you use fetchAuthSession() and just check it's not undefined?

golden drum
#

@loud tangle, sorry that we didn't get you a reply till now! Still want to get you a reply in the event this wasn't resolved yet.

In a v6 app using Next.js, you can call fetchAuthSession() to determine if the accessToken and iDTokens are defined as seen in an example here for server side usage:
https://docs.amplify.aws/gen1/react/build-a-backend/server-side-rendering/nextjs/#manage-auth-session-with-the-nextjs-middleware

Just for clarity, the getCurrentUser() is only going to check if there's a token in localStorage and won't care if the token is expired or not.

flint questBOT
#

✅ - How to tell if user is signed in?