Next.js Discord

Discord Forum

Auth process in NextJS

Unanswered
Savannah posted this in #help-forum
Open in Discord
SavannahOP
I never used auth in NextJS before. Right now I'm stuck with it and any help with be appreciated greatly. Story: I made a login form and connected it to a server action as nextjs documentation advises. In this action I make an API call to backend auth provider that returns a cookie with a jwt token. At first, I didn't see this cookie in my browser and thought that It was a bug. It was not, sadly. The cookie was assigned to the nextjs server. I wrote a function to forward it to client. It worked. But right now I don't know how to make use of server components because everytime I make a request I don't have this client cookie. Should I create another function that parses the jwt cookie and assigns it to the server before request? I think I'm doing something wrong.

I want to make my application as much server-side rendered as possible and make as little as possible requests to the database on my backend. What should I change?

I thought about switching to the onSubmit event on forms and client components everywhere where userdata is needed. Is this the way it works in NextJS? I worked with plain react before but auth there was a disaster. I stored jwt in localstorage or a context and made requests to backend everytime including the jwt itself.

Any advise is highly appreciated. I don't know where to store user data and how to deal with the components that require userdata. Please, help =(

P.S I don't plan on using NextJS as a backend. Telling just in case.

1 Reply

SavannahOP
In case the question is not clear, please tell me what else to include. I asked similar question on stackoverflow and got downvoted. I don't know where to look for