mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Add debug logging for auth troubleshooting
This commit is contained in:
1 parent
ae09fa8492
commit
ddb3ce214d
4 files changed
+25
-2
No files matched your search
@@ -71,7 +71,7 @@ export function createAuth(db: Database) {
|
||||
},
|
||||
advanced: {
|
||||
cookiePrefix: 'opencode',
|
||||
useSecureCookies: ENV.SERVER.NODE_ENV === 'production',
|
||||
useSecureCookies: ENV.AUTH.SECURE_COOKIES,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,17 @@ export function createAuthRoutes(auth: AuthInstance, _db: Database) {
|
||||
const app = new Hono()
|
||||
|
||||
app.all('/*', async (c) => {
|
||||
return auth.handler(c.req.raw)
|
||||
const response = await auth.handler(c.req.raw)
|
||||
|
||||
const setCookie = response.headers.get('set-cookie')
|
||||
if (c.req.path.includes('sign-in')) {
|
||||
logger.info(`Sign-in response - Status: ${response.status}, Set-Cookie: ${setCookie ? 'present' : 'missing'}`)
|
||||
if (setCookie) {
|
||||
logger.debug(`Set-Cookie header: ${setCookie.substring(0, 100)}...`)
|
||||
}
|
||||
}
|
||||
|
||||
return response
|
||||
})
|
||||
|
||||
return app
|
||||
|
||||
@@ -90,6 +90,7 @@ export const ENV = {
|
||||
AUTH: {
|
||||
SECRET: getEnvString('AUTH_SECRET', process.env.NODE_ENV === 'production' ? '' : generateDefaultSecret()),
|
||||
TRUSTED_ORIGINS: getEnvString('AUTH_TRUSTED_ORIGINS', 'http://localhost:5173,http://localhost:5003'),
|
||||
SECURE_COOKIES: getEnvBoolean('AUTH_SECURE_COOKIES', getEnvString('NODE_ENV', 'development') === 'production'),
|
||||
ADMIN_EMAIL: process.env.ADMIN_EMAIL,
|
||||
ADMIN_PASSWORD: process.env.ADMIN_PASSWORD,
|
||||
ADMIN_PASSWORD_RESET: getEnvBoolean('ADMIN_PASSWORD_RESET', false),
|
||||
|
||||
Reference in new issue
Block a user