Add debug logging for auth troubleshooting

This commit is contained in:
Chris Scott committed 2026-01-24 18:34:54 -05:00
1 parent ae09fa8492
commit ddb3ce214d
4 files changed
+25 -2

No files matched your search

+1 -1
View File
@@ -71,7 +71,7 @@ export function createAuth(db: Database) {
},
advanced: {
cookiePrefix: 'opencode',
useSecureCookies: ENV.SERVER.NODE_ENV === 'production',
useSecureCookies: ENV.AUTH.SECURE_COOKIES,
},
})
+12
View File
@@ -1,5 +1,6 @@
import { createMiddleware } from 'hono/factory'
import type { AuthInstance, Session } from './index'
import { logger } from '../utils/logger'
export function createAuthMiddleware(auth: AuthInstance) {
return createMiddleware<{
@@ -8,10 +9,21 @@ export function createAuthMiddleware(auth: AuthInstance) {
user: Session['user']
}
}>(async (c, next) => {
const cookies = c.req.header('cookie')
const origin = c.req.header('origin')
logger.debug(`Auth check - Path: ${c.req.path}, Origin: ${origin}, Has cookies: ${!!cookies}`)
if (cookies) {
const cookieNames = cookies.split(';').map(c => c.trim().split('=')[0]).join(', ')
logger.debug(`Cookie names: ${cookieNames}`)
}
const session = await auth.api.getSession({
headers: c.req.raw.headers,
})
logger.debug(`Session result: ${session ? 'found' : 'not found'}`)
if (!session) {
return c.json({ error: 'Unauthorized' }, 401)
}