简体   繁体   English

如何在 Next.js 中保持登录用户

[英]How to persist logged in user in Next.js

How can I possibly persist user data even after refresh?即使在刷新后,我如何才能保留用户数据? I was thinking about storing it inside local storage but that mean flash of unauthenticated content or storing it in cookie, but this would be very problematic when working with redux.我正在考虑将其存储在本地存储中,但这意味着未经身份验证的内容的 flash 或将其存储在 cookie 中,但这在使用 redux 时会出现很大问题。 I'm looking for a solution that will work with redux and will not cause unauthorized page content to show up.我正在寻找一种适用于 redux 并且不会导致未经授权的页面内容出现的解决方案。

You can use an npm package called Next Iron Session .您可以使用名为Next Iron Session 的 npm package It works really well with nextjs api and getServersideProps.它适用于 nextjs api 和 getServersideProps。 It's based on iron by Hapijs它基于Hapijs

You can use jwt in your Next.js project.您可以在 Next.js 项目中使用jwt

Please refer to this请参考这个

And there is a way to integrate Auth0 as well.还有一种方法可以集成Auth0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM