Next.js Discord

Discord Forum

NextAuth in Next 13 New User Callback

Answered
Tenterfield Terrier posted this in #help-forum
Open in Discord
Tenterfield TerrierOP
I am using Next 13 with Next Auth. I would like to call a webhook when a new user is created. How do I go about doing this?

I am reading this but I am not able to put it together with my implementation. I've attached my /app/api/auth/[...nextauth]/route.ts and /app/auth/signin/page.tsx
https://next-auth.js.org/configuration/callbacks

Thanks so much!
Answered by Tenterfield Terrier
Added this to [...nextauth]/route.ts

events: {
createUser: async ({ user }: { user: ExtendedUser }) => {
await fetch(
... );
},

Hopefully this can help the next person!
View full answer

5 Replies

Tenterfield TerrierOP
Solved. Thanks!
@Tenterfield Terrier Solved. Thanks!
did you do anything in particular to solve, or did you just change lots of things and it worked
@riský did you do anything in particular to solve, or did you just change lots of things and it worked
Tenterfield TerrierOP
Actually I had it all wrong...I didn't need to use a callback. I needed to use an event, the new User event.
Tenterfield TerrierOP
Added this to [...nextauth]/route.ts

events: {
createUser: async ({ user }: { user: ExtendedUser }) => {
await fetch(
... );
},

Hopefully this can help the next person!
Answer
Ohh nice 🎉