Skip to content

Commit 7a8c323

Browse files
ci: apply automated fixes
1 parent 296af64 commit 7a8c323

File tree

2 files changed

+56
-37
lines changed

2 files changed

+56
-37
lines changed

src/utils/auth.server-helpers.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export async function getCurrentUserFromRequest(request: Request) {
1919
const cookieData = await verifyCookie(signedCookie)
2020

2121
if (!cookieData) {
22-
console.error('[AUTH:ERROR] Session cookie verification failed - invalid signature or expired')
22+
console.error(
23+
'[AUTH:ERROR] Session cookie verification failed - invalid signature or expired',
24+
)
2325
return null
2426
}
2527

@@ -29,13 +31,17 @@ export async function getCurrentUserFromRequest(request: Request) {
2931
})
3032

3133
if (!user) {
32-
console.error(`[AUTH:ERROR] Session cookie references non-existent user ${cookieData.userId}`)
34+
console.error(
35+
`[AUTH:ERROR] Session cookie references non-existent user ${cookieData.userId}`,
36+
)
3337
return null
3438
}
3539

3640
// Verify session version matches (for session revocation)
3741
if (user.sessionVersion !== cookieData.version) {
38-
console.error(`[AUTH:ERROR] Session version mismatch for user ${user.id} - expected ${user.sessionVersion}, got ${cookieData.version}`)
42+
console.error(
43+
`[AUTH:ERROR] Session version mismatch for user ${user.id} - expected ${user.sessionVersion}, got ${cookieData.version}`,
44+
)
3945
return null
4046
}
4147

@@ -69,7 +75,9 @@ export async function getAuthenticatedUser() {
6975
const user = await getCurrentUserFromRequest(request)
7076

7177
if (!user) {
72-
console.error('[AUTH:ERROR] Authentication required but user not authenticated')
78+
console.error(
79+
'[AUTH:ERROR] Authentication required but user not authenticated',
80+
)
7381
throw new Error('Not authenticated')
7482
}
7583

src/utils/oauth.server.ts

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,43 @@ export async function upsertOAuthAccount(
4141
})
4242

4343
if (!user) {
44-
console.error(`[AUTH:ERROR] OAuth account exists for ${provider}:${profile.id} but user ${existingAccount.userId} not found`)
44+
console.error(
45+
`[AUTH:ERROR] OAuth account exists for ${provider}:${profile.id} but user ${existingAccount.userId} not found`,
46+
)
4547
throw new Error('User not found for existing OAuth account')
4648
}
4749

4850
if (user) {
49-
const updates: {
50-
email?: string
51-
name?: string
52-
image?: string
53-
} = {}
54-
55-
if (profile.email && user.email !== profile.email) {
56-
updates.email = profile.email
57-
}
58-
if (profile.name && user.name !== profile.name) {
59-
updates.name = profile.name
60-
}
61-
if (profile.image && user.image !== profile.image) {
62-
updates.image = profile.image
51+
const updates: {
52+
email?: string
53+
name?: string
54+
image?: string
55+
} = {}
56+
57+
if (profile.email && user.email !== profile.email) {
58+
updates.email = profile.email
59+
}
60+
if (profile.name && user.name !== profile.name) {
61+
updates.name = profile.name
62+
}
63+
if (profile.image && user.image !== profile.image) {
64+
updates.image = profile.image
65+
}
66+
67+
if (Object.keys(updates).length > 0) {
68+
await db
69+
.update(users)
70+
.set({ ...updates, updatedAt: new Date() })
71+
.where(eq(users.id, existingAccount.userId))
72+
}
6373
}
6474

65-
if (Object.keys(updates).length > 0) {
66-
await db
67-
.update(users)
68-
.set({ ...updates, updatedAt: new Date() })
69-
.where(eq(users.id, existingAccount.userId))
75+
return {
76+
userId: existingAccount.userId,
77+
isNewUser: false,
7078
}
7179
}
7280

73-
return {
74-
userId: existingAccount.userId,
75-
isNewUser: false,
76-
}
77-
}
78-
7981
// Find user by email (for linking multiple OAuth providers)
8082
const existingUser = await db.query.users.findFirst({
8183
where: eq(users.email, profile.email),
@@ -85,7 +87,9 @@ export async function upsertOAuthAccount(
8587

8688
if (existingUser) {
8789
// Link OAuth account to existing user
88-
console.log(`[AUTH:INFO] Linking ${provider} account to existing user ${existingUser.id} (${profile.email})`)
90+
console.log(
91+
`[AUTH:INFO] Linking ${provider} account to existing user ${existingUser.id} (${profile.email})`,
92+
)
8993
userId = existingUser.id
9094

9195
// Update user info if provided
@@ -109,7 +113,9 @@ export async function upsertOAuthAccount(
109113
}
110114
} else {
111115
// Create new user
112-
console.log(`[AUTH:INFO] Creating new user for ${provider} login: ${profile.email}`)
116+
console.log(
117+
`[AUTH:INFO] Creating new user for ${provider} login: ${profile.email}`,
118+
)
113119
const [newUser] = await db
114120
.insert(users)
115121
.values({
@@ -122,7 +128,9 @@ export async function upsertOAuthAccount(
122128
.returning()
123129

124130
if (!newUser) {
125-
console.error(`[AUTH:ERROR] Failed to create user for ${provider}:${profile.id} (${profile.email})`)
131+
console.error(
132+
`[AUTH:ERROR] Failed to create user for ${provider}:${profile.id} (${profile.email})`,
133+
)
126134
throw new Error('Failed to create user')
127135
}
128136

@@ -144,10 +152,13 @@ export async function upsertOAuthAccount(
144152
isNewUser: !existingUser,
145153
}
146154
} catch (error) {
147-
console.error(`[AUTH:ERROR] Failed to upsert OAuth account for ${provider}:${profile.id} (${profile.email}):`, {
148-
error: error instanceof Error ? error.message : 'Unknown error',
149-
stack: error instanceof Error ? error.stack : undefined,
150-
})
155+
console.error(
156+
`[AUTH:ERROR] Failed to upsert OAuth account for ${provider}:${profile.id} (${profile.email}):`,
157+
{
158+
error: error instanceof Error ? error.message : 'Unknown error',
159+
stack: error instanceof Error ? error.stack : undefined,
160+
},
161+
)
151162
throw error
152163
}
153164
}

0 commit comments

Comments
 (0)