{"record":{"id":"9fe016f2701cdcfb","repo":"eyaltoledano/claude-task-master","slug":"code-auth-failed","errorCode":"CODE_AUTH_FAILED","errorMessage":"`Token authentication failed: ${(error as Error).message}`","messagePattern":"`Token authentication failed: (.+?)`","errorType":"exception","errorClass":"AuthenticationError","httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/auth/services/session-manager.ts","lineNumber":293,"sourceCode":"\t\t\t\ttoken: session.access_token,\n\t\t\t\trefreshToken: session.refresh_token,\n\t\t\t\tuserId: user.id,\n\t\t\t\temail: user.email,\n\t\t\t\texpiresAt: session.expires_at\n\t\t\t\t\t? new Date(session.expires_at * 1000).toISOString()\n\t\t\t\t\t: undefined,\n\t\t\t\ttokenType: 'standard',\n\t\t\t\tsavedAt: new Date().toISOString(),\n\t\t\t\tselectedContext: context || undefined\n\t\t\t};\n\n\t\t\tthis.logger.info('Successfully authenticated with token');\n\t\t\treturn credentials;\n\t\t} catch (error) {\n\t\t\tif (error instanceof AuthenticationError) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new AuthenticationError(\n\t\t\t\t`Token authentication failed: ${(error as Error).message}`,\n\t\t\t\t'CODE_AUTH_FAILED'\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Verify MFA code and complete authentication\n\t * Call this after authenticateWithCode() throws MFA_REQUIRED error\n\t */\n\tasync verifyMFA(factorId: string, code: string): Promise<AuthCredentials> {\n\t\tawait this.waitForInitialization();\n\t\ttry {\n\t\t\tthis.logger.info('Verifying MFA code...');\n\n\t\t\t// Verify MFA code and get upgraded session\n\t\t\tconst session = await this.supabaseClient.verifyMFA(factorId, code);\n","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/auth/services/session-manager.ts#L275-L311","documentation":"AuthenticationError with code CODE_AUTH_FAILED thrown by authenticateWithCode's catch block for any exception that is not already an AuthenticationError. It wraps unexpected failures during one-time-token authentication (network errors, Supabase client exceptions, context store errors) with the original message interpolated.","triggerScenarios":"Calling authenticateWithCode(token) when any internal step throws outside the guarded AuthenticationError paths: fetch rejection to Supabase, malformed client initialization, exceptions in checkMFARequired() or contextStore.saveContext(), or a TypeError in the credentials-building code.","commonSituations":"Offline or proxied environments; misconfigured Supabase URL causing client-side errors; corrupted local auth/context storage causing saveContext to throw; a token containing characters that break the request unexpectedly.","solutions":["Read the interpolated underlying message to find the real failure point","Verify network reachability and Supabase client configuration (URL/keys)","Clear/corruption-check local auth context storage, then retry","Retry with a freshly generated one-time token after fixing the environment issue"],"exampleFix":"// before\nawait sessionManager.authenticateWithCode(token);\n// after: surface the underlying cause and retry once\ntry {\n  await sessionManager.authenticateWithCode(token);\n} catch (e) {\n  console.error('Code auth failed:', (e as Error).message);\n  await sessionManager.authenticateWithCode(await getFreshToken());\n}","handlingStrategy":"try-catch","validationCode":"if (!process.env.SUPABASE_URL) throw new Error('SUPABASE_URL not configured');\nconst token = rawToken?.trim();\nif (!token) throw new Error('One-time token required');","typeGuard":"function isCodeAuthFailed(e: unknown): e is AuthenticationError {\n  return e instanceof AuthenticationError && e.code === 'CODE_AUTH_FAILED';\n}","tryCatchPattern":"try {\n  await sessionManager.authenticateWithCode(token);\n} catch (e) {\n  if (isCodeAuthFailed(e)) {\n    logger.error('Token auth failed:', e.message); // includes root cause\n    await retryWithFreshToken();\n  } else throw e;\n}","preventionTips":["Log the full message — the wrapped cause identifies the failing step","Validate Supabase env config at startup","Clear corrupted local auth/context storage on repeated failures","Retry with a freshly generated one-time token, not the same one"],"tags":["auth","one-time-token","network","fallback-error"],"backgroundTag":"one-time-token-auth-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}