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 instance

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Run `tm auth` / the login flow to establish a session first
  2. Check session status (e.g. `tm auth status`) before calling updateContext
  3. If the token expired, trigger the refresh/login flow, then retry
  4. 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

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

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/659b0089397c6ccb. Report an issue: GitHub.