How can I configure something like nextauth `callbacks.signIn`?

When user signin by apple or google oauth, I want to query user information from my exists database, and verify that the user, and return new user information to session in nextauth I can do something like:
callbacks: {
async signIn(params) {
const { user, account, profile } = params
console.log("user:", params.user, params)

if (!user || !user.email || !account) {
return false
}

let ourUser = await getUserByEmail(user.email!)
if (!ourUser) {
ourUser = await createUser(account.provider!, user, profile)
}

// old mtbird auth
const myToken = signLogin(ourUser.id, user)
res.setHeader('Set-Cookie', `t=${myToken}`);
return true
},
}
callbacks: {
async signIn(params) {
const { user, account, profile } = params
console.log("user:", params.user, params)

if (!user || !user.email || !account) {
return false
}

let ourUser = await getUserByEmail(user.email!)
if (!ourUser) {
ourUser = await createUser(account.provider!, user, profile)
}

// old mtbird auth
const myToken = signLogin(ourUser.id, user)
res.setHeader('Set-Cookie', `t=${myToken}`);
return true
},
}
What should I do here?
2 Replies
KiNFiSH
KiNFiSH2w ago
This is what better auth does internally for you like creating a user and session even also validation as well. But you are looking to inspecting more you can hook in to databaseHook to trigger some actions before and after the user or session created.
Ping
Ping2w ago
@GeorgeZou Do you have any more questions? Otherwise I'll mark this post as solved.

Did you find this page helpful?