Skip to content

Commit 820d9fa

Browse files
authored
Merge pull request #3742 from liam-hq/devin/1760079394-add-auth-error-logging
feat: Add comprehensive error logging to authentication flows
2 parents 161d8c8 + 10ccc85 commit 820d9fa

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

frontend/apps/app/app/auth/callback/[provider]/route.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,18 @@ export async function GET(request: Request) {
2525
}
2626
return NextResponse.redirect(`${origin}${next}`)
2727
}
28+
console.error('OAuth callback code exchange failed:', {
29+
error: error.message,
30+
code: error.status,
31+
provider: request.url.includes('/github') ? 'github' : 'unknown',
32+
timestamp: new Date().toISOString(),
33+
})
34+
} else {
35+
console.error('OAuth callback missing code parameter:', {
36+
url: request.url,
37+
timestamp: new Date().toISOString(),
38+
})
2839
}
2940

30-
// On error, redirect to an error page with instructions
31-
return NextResponse.redirect(`${origin}/auth/auth-code-error`)
41+
return NextResponse.redirect(`${origin}/error`)
3242
}

frontend/apps/app/app/confirm/route.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ export async function GET(request: NextRequest) {
2222
// redirect user to specified redirect URL or root of app
2323
redirect(next)
2424
}
25+
console.error('Email confirmation OTP verification failed:', {
26+
error: error.message,
27+
type,
28+
timestamp: new Date().toISOString(),
29+
})
30+
} else {
31+
console.error('Email confirmation missing parameters:', {
32+
hasToken: !!token_hash,
33+
hasType: !!type,
34+
timestamp: new Date().toISOString(),
35+
})
2536
}
2637

2738
// redirect the user to an error page with some instructions

frontend/apps/app/components/LoginPage/services/loginByEmail.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ import { urlgen } from '../../../libs/routes/urlgen'
77
import { ensureUserHasOrganization } from './ensureUserHasOrganization'
88
import { sanitizeReturnPath } from './validateReturnPath'
99

10+
function maskEmail(email: string | undefined): string {
11+
if (!email || typeof email !== 'string') return '[invalid-email]'
12+
13+
const atIndex = email.indexOf('@')
14+
if (atIndex <= 0) return '[invalid-email]'
15+
16+
const localPart = email.substring(0, atIndex)
17+
const domain = email.substring(atIndex)
18+
19+
if (localPart.length <= 2) {
20+
return `${localPart[0]}*${domain}`
21+
}
22+
23+
return `${localPart[0]}${'*'.repeat(localPart.length - 2)}${localPart[localPart.length - 1]}${domain}`
24+
}
25+
1026
export async function loginByEmail(formData: FormData) {
1127
const supabase = await createClient()
1228

@@ -31,6 +47,11 @@ export async function loginByEmail(formData: FormData) {
3147

3248
const parsedData = v.safeParse(loginFormSchema, formDataObject)
3349
if (!parsedData.success) {
50+
console.error('Login validation failed:', {
51+
errors: parsedData.issues,
52+
emailMasked: maskEmail(formDataObject.email?.toString()),
53+
timestamp: new Date().toISOString(),
54+
})
3455
redirect(urlgen('error'))
3556
}
3657

@@ -39,6 +60,12 @@ export async function loginByEmail(formData: FormData) {
3960
const { error } = await supabase.auth.signInWithPassword(data)
4061

4162
if (error) {
63+
console.error('Login authentication failed:', {
64+
error: error.message,
65+
code: error.status,
66+
emailMasked: maskEmail(data.email),
67+
timestamp: new Date().toISOString(),
68+
})
4269
redirect(urlgen('error'))
4370
}
4471

frontend/apps/app/components/LoginPage/services/loginByGithub.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export async function loginByGithub(formData: FormData) {
6868
})
6969

7070
if (error) {
71+
console.error('GitHub OAuth initialization failed:', {
72+
error: error.message,
73+
redirectTo,
74+
timestamp: new Date().toISOString(),
75+
})
7176
redirect(urlgen('error'))
7277
}
7378

0 commit comments

Comments
 (0)