Next.js Discord

Discord Forum

How do I use JWT in Next.js

Answered
Rhinelander posted this in #help-forum
Open in Discord
RhinelanderOP
I made express REST API. If I go to "/auth/login" I get back access token and refresh token. What do I do with that in Next.js apart from storing them in cookies. I do not like context apporach as I want to SSR my pages. How do I check if token is valid? And when should I check if token is valid?
Answered by "use php"
Use [lucia auth](https://lucia-auth.com/)
View full answer

3 Replies

@Rhinelander I made express REST API. If I go to "/auth/login" I get back access token and refresh token. What do I do with that in Next.js apart from storing them in cookies. I do not like context apporach as I want to SSR my pages. How do I check if token is valid? And when should I check if token is valid?
when you handle your auth yourself, you normally know what you should need to do. If not, you shouldn't do it yourself. Yes, it's cool. Yea you want to maintain it. It's fine. And security is still a very very important part when it comes to auth. So, when I would be you, I would trust bulletproof systems like next auth that handle all the stuff for you.

This is a clear advice to NOT do auth yourself, when you don't know what you are doing.
RhinelanderOP
Well i do auth via OTP that user gets on their phone. It is passwordless. I didnt come across any other auth that does this. And since i use express nextauth might not be the best option
Answer