Authentication routing with NextJS and AWS Amplify 身份验证路由与NextJS和AWS Amplify

huangapple go评论50阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年4月20日 05:33:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76058965.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定