Skip to content

Commit cb5db66

Browse files
mjunaidcaclaude
andcommitted
debug(auth): Add JWT tenant_id logging to callback
When tokens are exchanged, decode and log the JWT's tenant_id and organization_ids to verify if SSO is returning the correct org after org switching. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d51638c commit cb5db66

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

  • apps/web/src/app/api/auth/callback

apps/web/src/app/api/auth/callback/route.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,23 @@ export async function GET(request: NextRequest) {
7171
const tokens = await tokenResponse.json();
7272
const expiresAt = Date.now() + (tokens.expires_in || 3600) * 1000;
7373

74-
// Debug logging
74+
// Debug logging - decode JWT to show tenant_id
7575
console.log("[Callback] Token exchange successful");
7676
console.log("[Callback] access_token present:", !!tokens.access_token);
7777
console.log("[Callback] id_token present:", !!tokens.id_token);
78-
console.log("[Callback] id_token is JWT:", tokens.id_token?.startsWith("eyJ"));
7978
if (tokens.id_token) {
80-
console.log("[Callback] id_token preview:", tokens.id_token.substring(0, 30) + "...");
79+
try {
80+
// Decode JWT payload (base64url decode middle part)
81+
const parts = tokens.id_token.split('.');
82+
if (parts.length === 3) {
83+
const payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString());
84+
console.log("[Callback] JWT tenant_id:", payload.tenant_id);
85+
console.log("[Callback] JWT organization_ids:", payload.organization_ids);
86+
console.log("[Callback] JWT sub:", payload.sub);
87+
}
88+
} catch (e) {
89+
console.log("[Callback] Could not decode JWT:", e);
90+
}
8191
}
8292

8393
// Create response with redirect to dashboard

0 commit comments

Comments
 (0)