nextAuth - Add to the user model

https://next-auth.js.org/adapters/models Hello, I'd like to add modify the user before it comes into the session callback in [..nextauth]
callbacks: {
async session({ session, user }) {
if (session.user) {
session.user.id = user.id;
}
callbacks: {
async session({ session, user }) {
if (session.user) {
session.user.id = user.id;
}
I found this but the authorize method never gets called: https://stackoverflow.com/questions/71185287/pass-more-data-to-session-in-next-auth is it a bad idea to overoptimze this and i should just make an extra prisma call here?
Models | NextAuth.js
NextAuth.js can be used with any database. Models tell you what structures NextAuth.js expects from your database. Models will vary slightly depending on which adapter you use, but in general, will look something like this. Each adapter's model/schema will be slightly adapted for its needs, but will look very much like this schema below:
Stack Overflow
Pass more data to session in Next-auth
We are doing OTP auth in our website. So in order to get authorized, a visitor enter his phone number in input and we send him a OPT number and he again enters the sent opt, then if it matches, we ...
14 Replies
shiroyasha9
shiroyasha92y ago
as far as i am aware, the link you have posted is the only correct way of doing it. If you need to pass any more data to the nextAuth callback, use jwtToken as mentioned
fotoflo
fotoflo2y ago
hmm @shiroyasha_ but it doesnt work...
fotoflo
fotoflo2y ago
fotoflo
fotoflo2y ago
the authorize debugger never fires and if i move authorize out
fotoflo
fotoflo2y ago
fotoflo
fotoflo2y ago
it also never fires
shiroyasha9
shiroyasha92y ago
@fotoflo this callback seems to have been renamed from authorize to signIn. Please check that once.
shiroyasha9
shiroyasha92y ago
the official docs for the same: https://next-auth.js.org/configuration/callbacks
Callbacks | NextAuth.js
Callbacks are asynchronous functions you can use to control what happens when an action is performed.
fotoflo
fotoflo2y ago
OOOOOOOO thank you! @shiroyasha_ ! but it doesn't work
callbacks: {
async session({ session, user }) {
if (session.user) {
session.user.id = user.id;
debugger; // gets called
if (session.user.lalala) {
debugger; // gets skipped
console.log("lalala: ", session.user.lalala);
}
}
async signIn({ user, account, profile, email, credentials }) {
const params = { user, account, profile, email, credentials };
params.user.lalala = "mo mo mo";
return await onSignin(params);
},`
},
callbacks: {
async session({ session, user }) {
if (session.user) {
session.user.id = user.id;
debugger; // gets called
if (session.user.lalala) {
debugger; // gets skipped
console.log("lalala: ", session.user.lalala);
}
}
async signIn({ user, account, profile, email, credentials }) {
const params = { user, account, profile, email, credentials };
params.user.lalala = "mo mo mo";
return await onSignin(params);
},`
},
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
fotoflo
fotoflo2y ago
@Geezer: i think it just has to return truthy/false - if i trutn the onSignin like this, its truthy so it goes on to execute session()
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
fotoflo
fotoflo2y ago
REALLY!? HAHHA ok let me check profile is a callback inside all of the providers?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server