Adding SignUp callback #4124
Replies: 5 comments 3 replies
-
Was this ever implemented? There is a Definitely a no-brainer feature to live somewhere amongst the auth. 👍 |
Beta Was this translation helpful? Give feedback.
-
yes please |
Beta Was this translation helpful? Give feedback.
-
This is implemented when creating/using an adapter, it should have a createUser function that is called when a new user tries to log in. read here And also, the pages object has a newUser property where you can redirect him when he registers to do w/e you want. E.g. you could redirect to an api that will redirect to the page you want, or redirect directly to that page. Auth docs However, I couldn't find anywhere in the docs when exactly that callback is fired. E.g. does the adapter immediately query for the user data in db, and if nothing is found automatically calls createUser, or maybe something else... Or rather it does say |
Beta Was this translation helpful? Give feedback.
-
For anyone looking for a workaround, you can get something without too much effort by wrapping the default methods of your desired adapater. Here's a rough example of how I've got a // /api/auth/[...nextauth]/route.ts
...
const DBAdapter = MongoDBAdapter(clientPromise)
export const authOptions: AuthOptions = {
/* Your other options here */
adapter: {
...DBAdapter,
createUser: (async user) => {
// Using non-null assertion as according to NextAuth this method is requried.
const createdUser = await DBAdapter.createUser!(user)
// Run whatever callbacks you want here
prePopulateUserData(createdUser);
return createdUser;
}
},
} Of course you can extend this to work for all the other methods used by your |
Beta Was this translation helpful? Give feedback.
-
这是自动回复的邮件。您好,我最近正在休假中,无法亲自回复你的邮件。我将在假期结束后,尽快给你回复。
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have been using NextAuth in a lot of my projects lately and faced some weird challenges while doing so. For example when I have multiple providers, or combined with credentials etc.
Usually what I want to do with my app is something like this:
LOGIN PAGE
It all works great 👍 but it gets kinda messy putting all that logic in, especially because different providers need different logic etc. I don't know if this has been asked before, but is it possible do add a SignUp function? It doesn't need to do anything special, it would just be for defining the SignUp callback logic and decoupling it from the SignIn logic.
Then my flow would be something like this:
LOGIN PAGE
REGISTRATION PAGE
Beta Was this translation helpful? Give feedback.
All reactions