Next.js: Traditional Authentication With Next

Created on 25 Jan 2017  路  4Comments  路  Source: vercel/next.js

I was studying some approaches to implement a traditional authentications on Next. In my brainstorms I found a solution that the user need be authenticate only on the first server-side rendering, once a time that every requests on client-side can return a Not Authenticate (403) error to be treated later with a redirect.

Can you guys think another approaches for that?

Most helpful comment

This is what i do:

  • when the user logs in client-side javascript sets a cookie in the browser conintaing the authentication bearer token
  • when making authenticated requests server-side (next.js) code reads the bearer token in the headers of the request of the browser and uses it to contact the api server on behalf of the client

All 4 comments

This is what i do:

  • when the user logs in client-side javascript sets a cookie in the browser conintaing the authentication bearer token
  • when making authenticated requests server-side (next.js) code reads the bearer token in the headers of the request of the browser and uses it to contact the api server on behalf of the client

Thanks @davibe for helping out! For the sake of having help from the community in one place, I'm forwarding you here: #153 and closing this thread.

@davibe would love it if you could replicate your message there if you haven't yet.
Thanks again!

hi @davibe i am saving my auth token in localstorage and then adding in headers from there but when server side request goes it did not set my autherization header.
Can you please suggest me some other way to set headers

If you set it as a cookie the server can read that cookie form headers. Have a look at how cookies work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

renatorib picture renatorib  路  3Comments

wagerfield picture wagerfield  路  3Comments

kenji4569 picture kenji4569  路  3Comments

formula349 picture formula349  路  3Comments

jesselee34 picture jesselee34  路  3Comments