Add Google provider to nextjauth
This commit is contained in:
@@ -26,6 +26,10 @@ const options = {
|
||||
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,
|
||||
@@ -33,10 +37,15 @@ const options = {
|
||||
jwt: true
|
||||
},
|
||||
callbacks: {
|
||||
jwt: async (token, user) => {
|
||||
jwt: async (token, user, account) => {
|
||||
if (user) {
|
||||
token.jwt = user.jwt
|
||||
token.user = user.user
|
||||
const response = await fetch(
|
||||
`${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)
|
||||
|
||||
Reference in New Issue
Block a user