5

After spending days of research, I can't really figure out how to handle the authentication routing with NextJS and AWS Amplify. This is the first time I'm using NextJS and I want to disable the login/register page for logged in users and disable the dashboard for not logged in users.

I already tried to check if user is authenticated with the AUTH api inside a middleware file but this didn't work. Searching on Google also didn't help because I wastn't be able to find anything related to this.

Hope someone can help me out.

1 Answer 1

1

Assuming you can successfully get a user info back from AWS Cognito (meaning you've configured your Amplify Cognito access properly), you need to use React Context Provider to have auth user information accessible for the whole app. Then, create some kinda route guard component and wrap your main app component in it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.