DEV Community

Discussion on: Using Credentials provider with a custom backend in NextAuth.js!

Collapse
bharath_ profile image
Bharath Radhakrishnan

Hello Twisha, I came here after one full days googling. I wanted to create a social media sign up button for a nextjs app with with what you call a custom laravel backend. The usage of ' pages/api/[..nextauth].js ' made me asking, where are they even using the custom backend .
So Just to confirm, even you have a custom backend you have to use pages/api feature in the app and define your auth providers there and call the custom backend api's from there right ?

Collapse
twisha profile image
Twisha Author

Hey Bharath,

If you are using a third party provider for authentication i.e Google, Facebook, Apple, Twitter etc. you don't need a custom backend as everything will be handled by nextauth.js.

If instead you want to use email-passsword login where the credentials are sent to your custom backend (in this case I'm assuming your Laravel app) then you can use the Credentials provider and configure it as it is explained in the article.

For third party provider logins (google, facebook, twitter etc.) nextauth has good documentation. For example this one is for Google -> next-auth.js.org/providers/google

Overall all the configurations for next-auth is in the pages/api/[..nextauth].js file.

Hope it answers your question :)

Collapse
bharath_ profile image
Bharath Radhakrishnan

What I actually wanted was to save the username, email ... fields after the google / signup to my own database. I think I figured it out. I am using the callbacks options inside the [...nextauth].js to call my api to pass username and email to my backend to store in my db.

Thread Thread
twisha profile image
Twisha Author

Ah okay I see what you mean, thanks for sharing your solution :)