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
Copy file name to clipboardExpand all lines: apps/webapp/app/models/user.server.ts
+37-3Lines changed: 37 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,19 @@ import {
9
9
}from"~/services/dashboardPreferences.server";
10
10
exporttype{User}from"@trigger.dev/database";
11
11
import{assertEmailAllowed}from"~/utils/email";
12
+
import{logger}from"~/services/logger.server";
13
+
14
+
exportclassAuthConflictErrorextendsError{
15
+
constructor(
16
+
message: string,
17
+
publicreadonlyexistingEmailUserId: string,
18
+
publicreadonlyexistingAuthUserId: string
19
+
){
20
+
super(message);
21
+
this.name="AuthConflictError";
22
+
}
23
+
}
24
+
12
25
typeFindOrCreateMagicLink={
13
26
authenticationMethod: "MAGIC_LINK";
14
27
email: string;
@@ -208,13 +221,12 @@ export async function findOrCreateGoogleUser({
208
221
});
209
222
210
223
if(existingEmailUser&&!existingUser){
211
-
// Link existing email account to Google auth
224
+
// Link existing email account to Google auth, preserving original authenticationMethod
212
225
constuser=awaitprisma.user.update({
213
226
where: {
214
227
email,
215
228
},
216
229
data: {
217
-
authenticationMethod: "GOOGLE",
218
230
authenticationProfile: authProfile,
219
231
authenticationExtraParams: authExtraParams,
220
232
avatarUrl,
@@ -229,12 +241,34 @@ export async function findOrCreateGoogleUser({
229
241
}
230
242
231
243
if(existingEmailUser&&existingUser){
232
-
// User already linked to Google, update profile info
244
+
// Check if email user and auth user are the same
245
+
if(existingEmailUser.id!==existingUser.id){
246
+
// Different users: email is taken by one user, Google auth belongs to another
247
+
logger.error(
248
+
`Google auth conflict: Google ID ${authenticationProfile.id} belongs to user ${existingUser.id} but email ${email} is taken by user ${existingEmailUser.id}`,
0 commit comments