diff --git a/package.json b/package.json index 239f0fc..741d808 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ { "capIsNewExceptions": [ "Credentials", + "Google", "NextAuth" ] } diff --git a/pages/api/auth/[...nextauth].js b/pages/api/auth/[...nextauth].js index 5d73926..162b98f 100644 --- a/pages/api/auth/[...nextauth].js +++ b/pages/api/auth/[...nextauth].js @@ -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)