toeverything/AFFiNE · error · AuthSessionError

AUTH_SESSION_EMPTY

AUTH_SESSION_EMPTY

Error message

AUTH_SESSION_EMPTY

What it means

withAuthRetry throws AuthSessionError('AUTH_SESSION_EMPTY') when the broker returns no valid access token, indicating there is no stored session to authenticate the request with and the caller must sign in.

Source

Thrown at packages/common/auth/src/token-broker.ts:409

    'code' in error &&
    typeof error.code === 'string'
      ? error.code
      : 'AUTH_SESSION_TEMPORARILY_UNAVAILABLE';
  const publicCode = PUBLIC_AUTH_CODES.has(code)
    ? code
    : 'AUTH_SESSION_TEMPORARILY_UNAVAILABLE';
  return new AuthSessionError(
    publicCode,
    !PERMANENT_AUTH_CODES.has(publicCode)
  );
}

export async function withAuthRetry<T>(
  broker: AuthTokenBrokerContract,
  request: (accessToken: string) => Promise<T>
) {
  const token = await broker.getValidAccessToken();
  if (!token) throw new AuthSessionError('AUTH_SESSION_EMPTY', false);
  try {
    return await request(token);
  } catch (error) {
    const classified = classifyAuthError(error);
    if (classified.code !== 'ACCESS_TOKEN_EXPIRED') throw classified;
    const pair = await broker.refresh('access-token-expired');
    return await request(pair.accessToken);
  }
}

export function createRealtimeAuthAdapter(broker: AuthTokenBrokerContract) {
  return {
    getAccessToken: () => broker.getValidAccessToken(120_000),
    recover: async (error: unknown) => {
      const classified = classifyAuthError(error);
      if (classified.code !== 'ACCESS_TOKEN_EXPIRED') throw classified;
      return (await broker.refresh('realtime-access-token-expired'))
        .accessToken;

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Sign in again; the stored auth session is empty or was cleared.
  2. Check that session storage (cookies/keychain) is available and not blocked.
  3. Restart the app if the session state is corrupted.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/common/auth/src/token-broker.ts:409 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18). Data as JSON: /api/errors/ce279ba3066fffd6. Report an issue: GitHub.