-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to pass additional values to signIn()
callback while using oauth in Authjs ( beta v5 )
#11387
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: |
@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;
},
} |
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. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
The text was updated successfully, but these errors were encountered: