简体   繁体   中英

How can I maintain logged in my Nextjs App

How can I make sure that regular users do not have to log in every time they load the website in a NextJs (ReactJs) environment?

This is a big topic and it depends on how you handle sessions / access rights in your website.

One approach is that your server will provide an access token that is stored in a cookie or in the local storage of the browser. Then with each request this access token can be passed to the server.

Please note that you need to be careful when implementing this so that your site is not vulnerable to XSS attacks.

There are many tutorials online that will teach you to do this in NextJs.

Here is an example of how to implement safe cookie based authentication in NextJs using passport-library: https://github.com/vercel/next.js/tree/canary/examples/with-passport

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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