How to do something on register (sign up) in NextAuth?!
There's only signIn callback, and I haven't found a way to check if the user is signing in for the first time. I want to send a "thank you for registering" email.
How do I do it?
6 Replies
add a database field (or separate table) and check for that
There is a variable for the jwt callback called
isNewUser
that might work:
https://next-auth.js.org/configuration/callbacks#jwt-callbackCallbacks | NextAuth.js
Callbacks are asynchronous functions you can use to control what happens when an action is performed.
The answer cje provided is probably the full-proof way
I have nowhere to add it if I cannot do something on register
right?
Il'l try doing it through JWT as joerambo suggested
Where would that flag be stored according to you
Well, the JWT way works. The isNewUser field is not set for signin using CredentialsProvider, but I'm alright with that.
Thank you both for helping me, appreciate it.