NextAuth with google provider
Unanswered
Giant panda posted this in #help-forum
Giant pandaOP
Hi guys, i have configured the NextAuth in my project.
Currently i have implemented the credentials providers where i also pass a rolein signIn function like this
SignIn("credentials",{email:"", password:"",role:"A" }
The role could be "A" or "B"
In an another page the role B also and i am handling the logic in options route.
Now i want to do the same in signIn("google")
Function but how can i set the role as A?
The roles is set upon the url if it contains sn A route then role is A else Role is .
#next-auth #google
Currently i have implemented the credentials providers where i also pass a rolein signIn function like this
SignIn("credentials",{email:"", password:"",role:"A" }
The role could be "A" or "B"
In an another page the role B also and i am handling the logic in options route.
Now i want to do the same in signIn("google")
Function but how can i set the role as A?
The roles is set upon the url if it contains sn A route then role is A else Role is .
#next-auth #google
6 Replies
If the only options are role A or B, you can just hard code it in the next-auth options
//for sign in with credentials
CredentialsProvider({
async authorize(credentials){
const [response, error] = await login(...credentials, role: "A")
}
})
//for sign in with google
callbacks: {
async jwt({account}){
if(account.provider === 'google'){
const [response, error] await loginWithGoogle(account.access_token, role: "B")
}
}
}
//for sign in with credentials
CredentialsProvider({
async authorize(credentials){
const [response, error] = await login(...credentials, role: "A")
}
})
//for sign in with google
callbacks: {
async jwt({account}){
if(account.provider === 'google'){
const [response, error] await loginWithGoogle(account.access_token, role: "B")
}
}
}
@beamer boy If the only options are role A or B, you can just hard code it in the next-auth options
//for sign in with credentials
CredentialsProvider({
async authorize(credentials){
const [response, error] = await login(...credentials, role: "A")
}
})
//for sign in with google
callbacks: {
async jwt({account}){
if(account.provider === 'google'){
const [response, error] await loginWithGoogle(account.access_token, role: "B")
}
}
}
Giant pandaOP
there are 2 type of user for when signin with google. how can i track it?
for credentails i can send userA and userB but ho can i send n signin("google")
for credentails i can send userA and userB but ho can i send n signin("google")
@beamer boy
well, that means we have the same problem hahaha, I am also trying to pass custom value in the callback function but unfortunately that is not possible, I found some workaround to store it on the cookies then use it on next-auth options
if you're not using app directory, you can set the next-auth to advance initialization so you can get the query params and use it on the callback