Add Google provider to nextjauth
This commit is contained in:
@@ -56,6 +56,7 @@
|
|||||||
{
|
{
|
||||||
"capIsNewExceptions": [
|
"capIsNewExceptions": [
|
||||||
"Credentials",
|
"Credentials",
|
||||||
|
"Google",
|
||||||
"NextAuth"
|
"NextAuth"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ const options = {
|
|||||||
throw new Error(errorMessage)
|
throw new Error(errorMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}),
|
||||||
|
Providers.Google({
|
||||||
|
clientId: process.env.GOOGLE_CLIENT_ID,
|
||||||
|
clientSecret: process.env.GOOGLE_CLIENT_SECRET
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
database: process.env.NEXT_PUBLIC_DATABASE_URL,
|
database: process.env.NEXT_PUBLIC_DATABASE_URL,
|
||||||
@@ -33,10 +37,15 @@ const options = {
|
|||||||
jwt: true
|
jwt: true
|
||||||
},
|
},
|
||||||
callbacks: {
|
callbacks: {
|
||||||
jwt: async (token, user) => {
|
jwt: async (token, user, account) => {
|
||||||
if (user) {
|
if (user) {
|
||||||
token.jwt = user.jwt
|
const response = await fetch(
|
||||||
token.user = user.user
|
`${process.env.NEXT_PUBLIC_API_URL}/auth/${account.provider}/callback?access_token=${account?.accessToken}`
|
||||||
|
)
|
||||||
|
const data = await response.json()
|
||||||
|
token.id = data.id || user.id
|
||||||
|
token.jwt = data.jwt || user.jwt
|
||||||
|
token.user = data.user || user.user
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve(token)
|
return Promise.resolve(token)
|
||||||
|
|||||||
Reference in New Issue
Block a user