Replies: 3 comments
-
I don't think that you can pass custom arguments to the You can extend the user session by adding the // ...
callbacks: {
async session({token, session}) {
if (token.role && session.user) {
session.user.role = token.role
}
}
// ...
} There's a dedicated video about next auth v5: |
Beta Was this translation helpful? Give feedback.
-
@Jay-Karia I am adding that already . During the sign-up progress , I need to get that additional argument from the user to create a entity with specified role . callbacks: {
async signIn({ profile, user, account, credentials, ...other }) {
const email = profile?.email;
const name = profile?.name;
const image = profile?.picture
const phoneNumber = profile?.phone_number;
const address = profile?.address?.formatted + ", " + profile?.address?.locality + ", " + profile?.address?.region + ", " + profile?.address?.country;
// i want to get this arguement from the user
const is_institute = false
let response = await getUserFromEmail({ email: email ?? null });
let userData;
if (response) {
userData = response;
} else {
userData = await createUser({
email: email ?? null,
name: name ?? null,
image: image ?? null,
phoneNumber: phoneNumber ?? null,
address: address ?? null,
is_institute: is_institute
})
}
if (userData) {
return true;
}
return false;
},
async jwt({ profile, token }) {
const email = profile?.email;
if (email) {
const user = await getUserFromEmail({ email: email ?? null });
if (user) {
token.id = user?.id;
token.name = user?.name;
token.email = user?.email;
token.is_institute = user?.is_institute;
token.image = user?.image;
}
}
return token;
},
async session({ session, token }) {
session.user.id = token?.id as string;
session.user.name = token.name as string;
session.user.email = token.email as string;
session.user.is_institute = token.is_institute as boolean;
session.user.image = token.image as string;
return session;
},
} |
Beta Was this translation helpful? Give feedback.
-
Okay, We will get the // actions/register.ts
export const register = async (values: z.infer<typeof registerSchema>) => {
// validate data
// ...
// hash password
// ...
await db.user.create({
data: {
name: validatedValues.name.toLowerCase(),
email: validatedValues.email,
password: hashedPassword,
role: validatedValues.role // getting the role from form input
}
})
// ...
return { msg: "User successfully registered, verify your email", status: "success" }
} This function will create a user in database with the role specified in the form. |
Beta Was this translation helpful? Give feedback.
-
What is the improvement or update you wish to see?
Using Auth.js ( next-auth v5 beta)
I am using Google Ouath , and building a role based sign-up , user can either sign-up as user or organization . I want to pass a additional param to the signIn("google") funation specifiing the role of the user. This will help me to create respective entity in the signIn callback
Is there any context that might help us understand?
I wasn't able to find any piece of information on
Auth.js
docs.Does the docs page already exist? Please link to it.
No response
Beta Was this translation helpful? Give feedback.
All reactions