eyaltoledano/claude-task-master · error · AuthenticationError
NOT_AUTHENTICATED
NOT_AUTHENTICATED
Error message
Not authenticated
What it means
updateContext persists the org/brief selection into the stored user context, but refuses to do so when no valid authenticated session exists. It throws AuthenticationError with code NOT_AUTHENTICATED rather than silently writing context that would be orphaned.
Source
Thrown at packages/tm-core/src/modules/auth/managers/auth-manager.ts:284
* Get stored user context (userId, email)
*/
getStoredContext() {
return this.sessionManager.getStoredContext();
}
/**
* Get the current user context (org/brief selection)
*/
getContext(): UserContext | null {
return this.contextStore.getUserContext();
}
/**
* Update the user context (org/brief selection)
*/
async updateContext(context: Partial<UserContext>): Promise<void> {
if (!(await this.hasValidSession())) {
throw new AuthenticationError('Not authenticated', 'NOT_AUTHENTICATED');
}
this.contextStore.updateUserContext(context);
}
/**
* Clear the user context
*/
async clearContext(): Promise<void> {
if (!(await this.hasValidSession())) {
throw new AuthenticationError('Not authenticated', 'NOT_AUTHENTICATED');
}
this.contextStore.clearUserContext();
}
/**
* Get the organization service instanceView on GitHub (pinned to c0c98d367c)
Solutions
- Run `tm auth` / the login flow to establish a session first
- Check session status (e.g. `tm auth status`) before calling updateContext
- If the token expired, trigger the refresh/login flow, then retry
- Catch AuthenticationError with code NOT_AUTHENTICATED and route the user to login
Example fix
// before
await auth.updateContext({ briefId });
// after
if (!(await auth.hasValidSession())) await auth.authenticate();
await auth.updateContext({ briefId }); Defensive patterns
Strategy: validation
Validate before calling
const authenticated = await authManager.hasValidSession();
if (!authenticated) await runLoginFlow();
await authManager.updateContext({ orgId, briefId }); Type guard
function isNotAuthenticatedError(e: unknown): e is AuthenticationError {
return e instanceof AuthenticationError && e.code === 'NOT_AUTHENTICATED';
} Try / catch
try {
await auth.updateContext(ctx);
} catch (e) {
if (isNotAuthenticatedError(e)) {
await auth.authenticate();
await auth.updateContext(ctx);
} else throw e;
} Prevention
- Check hasValidSession() before any context mutation
- Proactively refresh or re-login when tokens approach expiry
- Never assume a context file copied between machines carries valid sessions
- Route users through the login flow on first run of the CLI
When it happens
Trigger: Calling authManager.updateContext({ orgId, briefId }) when there is no session, the session has expired, or tokens failed refresh (hasValidSession() returns false).
Common situations: User never ran `tm auth login`; access token expired and refresh failed; context file was copied to another machine without valid tokens; clock skew invalidating JWT expiry.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- REFRESH_FAILED
- REFRESH_FAILED
- SESSION_SET_FAILED
- AUTH_REQUIRED
- No refresh token received from server - session refresh will
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/659b0089397c6ccb.
Report an issue: GitHub.