英文:
Authentication routing with NextJS and AWS Amplify
问题
经过多天的研究,我真的搞不清楚如何处理NextJS和AWS Amplify的身份验证路由。这是我第一次使用NextJS,我想要为已登录的用户禁用登录/注册页面,并为未登录的用户禁用仪表板。
我已经尝试在中间件文件中使用AUTH API检查用户是否已经认证,但这没有起作用。在Google上搜索也没有帮助,因为我找不到与此相关的信息。
希望有人能帮助我解决这个问题。
英文:
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
得分: 0
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.
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论