Skip to content

Commit bd8e136

Browse files
committed
Merge branch 'features/AIChatBot-ONGOING' of https://github.com/lab68dev/lab68dev-platform into features/AIChatBot-ONGOING
2 parents d550058 + f3701b8 commit bd8e136

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

app/auth/callback/route.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,27 @@ export async function GET(request: NextRequest) {
6363
.eq('email', user.email)
6464
.single()
6565

66+
// Handle potential errors from the user lookup
67+
if (userError) {
68+
// Supabase returns code 'PGRST116' when .single() finds no rows (i.e., user not found)
69+
if (userError.code === 'PGRST116') {
70+
console.log('ℹ️ User not found in database (expected for new user):', userError.message)
71+
} else {
72+
console.error('❌ Error checking if user exists in database:', userError)
73+
return NextResponse.redirect(
74+
`${origin}/login?error=user_lookup_failed&message=${encodeURIComponent(userError.message)}`
75+
)
76+
}
77+
}
78+
if (userError) {
79+
console.error('❌ Error checking if user exists:', userError)
80+
return NextResponse.redirect(
81+
`${origin}/login?error=user_lookup_failed&message=${encodeURIComponent(
82+
userError.message,
83+
)}`,
84+
)
85+
}
86+
6687
// If user doesn't exist in our users table, redirect to signup to complete profile
6788
if (!existingUser) {
6889
console.log('👤 New user detected, redirecting to signup...')

lib/database/connection.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,14 @@ export async function searchUsers(query: string, limit = 10) {
334334

335335
if (!trimmedQuery) return []
336336

337+
// Sanitize query to avoid injecting special characters into filter expression
338+
const safeQuery = trimmedQuery.replace(/[,%()]/g, '')
339+
337340
// Search by email or name (case-insensitive)
338341
const { data, error } = await supabase
339342
.from('profiles')
340343
.select('id, email, name, avatar')
341-
.or(`email.ilike.%${trimmedQuery}%,name.ilike.%${trimmedQuery}%`)
344+
.or(`email.ilike.%${safeQuery}%,name.ilike.%${safeQuery}%`)
342345
.limit(limit)
343346

344347
if (error) {

0 commit comments

Comments
 (0)