Next.js Discord

Discord Forum

How to do Next.js authentication with an external API?

Answered
Red-necked Grebe posted this in #help-forum
Open in Discord
Original message was deleted.
Answered by `${ViNoS}`
idk the best approach, but for me I used 2 different approaches:
1- the easiest one is leaving any part of app that needs these data to render on the client side in a useEffect

2- which is bit more complicated, i switched from sending auth token in cookies to headers, and for the login , you send the token in the response body
then since I store it in the cookies (from the client side, not the api), then this cookie will be sent the next server so you retrieve it and use it in the headers of your app

not sure if these methods are effecient but well...
View full answer

1 Reply

Avatar
idk the best approach, but for me I used 2 different approaches:
1- the easiest one is leaving any part of app that needs these data to render on the client side in a useEffect

2- which is bit more complicated, i switched from sending auth token in cookies to headers, and for the login , you send the token in the response body
then since I store it in the cookies (from the client side, not the api), then this cookie will be sent the next server so you retrieve it and use it in the headers of your app

not sure if these methods are effecient but well...
Answer