From 0c1008d7257c67a9d9f323a27512d7e67f54aebd Mon Sep 17 00:00:00 2001 From: Till-JS <101404291+Till-JS@users.noreply.github.com> Date: Thu, 29 Jan 2026 12:51:56 +0100 Subject: [PATCH] debug(auth): add detailed logging for OIDC handler response Co-Authored-By: Claude Opus 4.5 --- .../src/auth/services/better-auth.service.ts | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/services/mana-core-auth/src/auth/services/better-auth.service.ts b/services/mana-core-auth/src/auth/services/better-auth.service.ts index 4621974df..94bc234d4 100644 --- a/services/mana-core-auth/src/auth/services/better-auth.service.ts +++ b/services/mana-core-auth/src/auth/services/better-auth.service.ts @@ -1255,6 +1255,11 @@ export class BetterAuthService { // Call Better Auth's handler const response = await this.auth.handler(fetchRequest); + console.log('[handleOidcRequest] Better Auth status:', response.status); + console.log( + '[handleOidcRequest] Better Auth headers:', + Object.fromEntries(response.headers.entries()) + ); // Convert Response to our format const responseHeaders: Record = {}; @@ -1262,13 +1267,22 @@ export class BetterAuthService { responseHeaders[key] = value; }); - // Get body + // Get body - handle empty responses let body: unknown; const contentType = response.headers.get('content-type'); - if (contentType?.includes('application/json')) { - body = await response.json(); + const textBody = await response.text(); + console.log('[handleOidcRequest] Response body length:', textBody.length); + console.log('[handleOidcRequest] Response body preview:', textBody.substring(0, 500)); + + if (contentType?.includes('application/json') && textBody.length > 0) { + try { + body = JSON.parse(textBody); + } catch { + console.warn('[handleOidcRequest] Failed to parse JSON, using text body'); + body = textBody; + } } else { - body = await response.text(); + body = textBody; } return {