Help with authentication
Unanswered
johndoe7144 posted this in #help-forum
Hello! I'm extremely new to this field and I've been trying to implement authentication without using any authentication libraries as I want to learn how it works
My backend is in express.js and my frontend is in nextjs (it's an election management app)
There are lots of issues and hacky things with this that I can't seem to solve, please help me with that:
* Do I use cookies to store access and refresh tokens or do i use localstorage for it (I'm currently using localstorage)? (There's cookie code above but that was just me testing it)
* If I want to access the voter profile, do I send a request to the backend with the access token, decrypt the jwt, find the user id stored in it, get the user profile from the db and send it back?
* Or, do I just decrypt the jwt in the frontend (the jwt already has the email and the role, the only 2 things that I actually need) and not get the backend involved with this? The
* If I want to implement sessions, (I'm new to this concept) how would I do it?
more details (with code): https://www.reddit.com/r/nextjs/comments/14mthud/handling_authentication/
My backend is in express.js and my frontend is in nextjs (it's an election management app)
There are lots of issues and hacky things with this that I can't seem to solve, please help me with that:
* Do I use cookies to store access and refresh tokens or do i use localstorage for it (I'm currently using localstorage)? (There's cookie code above but that was just me testing it)
* If I want to access the voter profile, do I send a request to the backend with the access token, decrypt the jwt, find the user id stored in it, get the user profile from the db and send it back?
* Or, do I just decrypt the jwt in the frontend (the jwt already has the email and the role, the only 2 things that I actually need) and not get the backend involved with this? The
verifyAccessToken function sends the token and just retrieves the data from the backend like i mentioned* If I want to implement sessions, (I'm new to this concept) how would I do it?
more details (with code): https://www.reddit.com/r/nextjs/comments/14mthud/handling_authentication/
2 Replies
@johndoe7144 Auth.js(next-auth) is a de facto standard lib to implement auth(OAuth).
Most of them are done by Auth.js First off, go through the doc and play around with demo.
https://authjs.dev/
Most of them are done by Auth.js First off, go through the doc and play around with demo.
https://authjs.dev/
i mean that you will see so many questions about Auth.js in this Discord server, which means you will learn a lot of things about authentication/authorization in the course of working with Auth.js