Next.js Discord

Discord Forum

Nextjs JWT authentication with no libraries (Only fetch)

Answered
OxyGen posted this in #help-forum
Open in Discord
Hey guys, I'm trying to build authentication with no libraries. So I'm on the way of refetching user on each page after reloading or logging in and refreshing access token on expire.
I'm sending the request on each page in navbar to get user from backend and set user state in zustand store. In case of refreshing access token. I'm refreshing it when I receive 403 error.
I've question can somebody explain the logic. Because I think my approach is not good
Answered by aardani
and can declare duration on how old data is considered fresh
View full answer

19 Replies

You said with no libraries but then you mentioned zustand
what is the issue?
I mean no libraries such as Next auth or axios
what session storing strategy did you use? database session id or jwt?
Sorry for confusion. I use jwt
what is your approach? why do you think its not good?
I think that sending request to get user on each page is not good. Maybe there is better solution. But I didn't find out so I ask this question
just get user from jwt
Because user's username, picture and other stuff is getting from backend
but the sessionid is store din jwt right?
@aardani but the sessionid is store din jwt right?
userid is stored in jwt
@OxyGen userid is stored in jwt
does zustand provide client-side caching?
because RQ and useSWR does
so that you dont ened to fetch every navigation
and can declare duration on how old data is considered fresh
Answer
is it the same as revalidation in fetch?
revalidation is server-side caching