Tuesday 3 November 2020

NextJs Authentication with Next-Auth against DRF

I have an exiting Django project that I am trying to move from templates to NextJs frontend. I came across Next-Auth-js which seems to be nice in Next Auth.

However, the doc seems to focus more with JS related Backend Auth. Following this example I have sent the NEXTAUTH_URL environment variable to my DRF Endpoint localhost:8002. While the frontend runs on localhost:3000. While my _app.js looks like this:

<Provider options= session={pageProps.session}  >
  <Component {...pageProps} />
</Provider>

Using the Nav.js for a test, I changed the signin/out href to point to my Django endpoints but it seems next-auth-js ignores this and places a session fetch to my frontend http://localhost:3000/api/auth/session instead of the the http://localhost:8002/api/auth/session.

I will appreciate any assistance on how I can correctly/securely implement this authentication using Django Rest Framework (DRF)



from NextJs Authentication with Next-Auth against DRF

No comments:

Post a Comment