fixed issue with mixed up Google login, profile.id is undefined and this is causing the first record to be retrieved instead of the AND query failing (#1569)

(cherry picked from commit 4f168616e7b7a0a03b979b434b4aa20c7b612cb0)
This commit is contained in:
Deepak Prabhakara 2022-01-20 01:24:00 +00:00 committed by GitHub
parent 745fadab2f
commit e0a923979a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -150,7 +150,7 @@ export default NextAuth({
}, },
providers, providers,
callbacks: { callbacks: {
async jwt({ token, user, account, profile }) { async jwt({ token, user, account }) {
if (!user) { if (!user) {
return token; return token;
} }
@ -165,7 +165,7 @@ export default NextAuth({
// The arguments above are from the provider so we need to look up the // The arguments above are from the provider so we need to look up the
// user based on those values in order to construct a JWT. // user based on those values in order to construct a JWT.
if (account && profile && account.type === "oauth" && account.provider) { if (account && account.type === "oauth" && account.provider && account.providerAccountId) {
let idP: IdentityProvider = IdentityProvider.GOOGLE; let idP: IdentityProvider = IdentityProvider.GOOGLE;
if (account.provider === "saml") { if (account.provider === "saml") {
idP = IdentityProvider.SAML; idP = IdentityProvider.SAML;
@ -178,7 +178,7 @@ export default NextAuth({
identityProvider: idP, identityProvider: idP,
}, },
{ {
identityProviderId: profile.id as string, identityProviderId: account.providerAccountId as string,
}, },
], ],
}, },