You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Link existing email account to Google auth, preserving original authenticationMethod
214
+
constuser=awaitprisma.user.update({
215
+
where: {
216
+
email,
217
+
},
218
+
data: {
219
+
authenticationProfile: authProfile,
220
+
authenticationExtraParams: authExtraParams,
221
+
avatarUrl,
222
+
authIdentifier,
223
+
},
224
+
});
225
+
226
+
return{
227
+
user,
228
+
isNewUser: false,
229
+
};
230
+
}
231
+
232
+
if(existingEmailUser&&existingUser){
233
+
// Check if email user and auth user are the same
234
+
if(existingEmailUser.id!==existingUser.id){
235
+
// Different users: email is taken by one user, Google auth belongs to another
236
+
logger.error(
237
+
`Google auth conflict: Google ID ${authenticationProfile.id} belongs to user ${existingUser.id} but email ${email} is taken by user ${existingEmailUser.id}`,
238
+
{
239
+
email,
240
+
existingEmailUserId: existingEmailUser.id,
241
+
existingAuthUserId: existingUser.id,
242
+
authIdentifier,
243
+
}
244
+
);
245
+
246
+
return{
247
+
user: existingUser,
248
+
isNewUser: false,
249
+
};
250
+
}
251
+
252
+
// Same user: update all profile fields
253
+
constuser=awaitprisma.user.update({
254
+
where: {
255
+
id: existingUser.id,
256
+
},
257
+
data: {
258
+
email,
259
+
displayName,
260
+
name,
261
+
avatarUrl,
262
+
authenticationProfile: authProfile,
263
+
authenticationExtraParams: authExtraParams,
264
+
},
265
+
});
266
+
267
+
return{
268
+
user,
269
+
isNewUser: false,
270
+
};
271
+
}
272
+
273
+
// When the IDP user (Google) already exists, the "update" path will be taken and the email will be updated
274
+
// It's not possible that the email is already taken by a different user because that would have been handled
0 commit comments