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
cje
cje2y ago
add a database field (or separate table) and check for that
jdsl
jdsl2y ago
There is a variable for the jwt callback called isNewUser that might work: https://next-auth.js.org/configuration/callbacks#jwt-callback
Callbacks | NextAuth.js
Callbacks are asynchronous functions you can use to control what happens when an action is performed.
jdsl
jdsl2y ago
The answer cje provided is probably the full-proof way
The contents user, account, profile and isNewUser will vary depending on the provider and if you are using a database.
The contents user, account, profile and isNewUser will vary depending on the provider and if you are using a database.
aspireone
aspireoneOP2y ago
I have nowhere to add it if I cannot do something on register right? Il'l try doing it through JWT as joerambo suggested
cje
cje2y ago
signIn() {
const userDoneRegistering = something();
if (!userDoneRegistering) {
doUserRegistrationStuff();
}
}

doUserRegistrationStuff() {
doStuff();
setUserDoneRegistering();
}
signIn() {
const userDoneRegistering = something();
if (!userDoneRegistering) {
doUserRegistrationStuff();
}
}

doUserRegistrationStuff() {
doStuff();
setUserDoneRegistering();
}
aspireone
aspireoneOP2y ago
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.
Want results from more Discord servers?
Add your server