{"record":{"id":"ce279ba3066fffd6","repo":"toeverything/AFFiNE","slug":"auth-session-empty","errorCode":"AUTH_SESSION_EMPTY","errorMessage":"AUTH_SESSION_EMPTY","messagePattern":"AUTH_SESSION_EMPTY","errorType":"error_code","errorClass":"AuthSessionError","httpStatus":null,"severity":"error","filePath":"packages/common/auth/src/token-broker.ts","lineNumber":409,"sourceCode":"    'code' in error &&\n    typeof error.code === 'string'\n      ? error.code\n      : 'AUTH_SESSION_TEMPORARILY_UNAVAILABLE';\n  const publicCode = PUBLIC_AUTH_CODES.has(code)\n    ? code\n    : 'AUTH_SESSION_TEMPORARILY_UNAVAILABLE';\n  return new AuthSessionError(\n    publicCode,\n    !PERMANENT_AUTH_CODES.has(publicCode)\n  );\n}\n\nexport async function withAuthRetry<T>(\n  broker: AuthTokenBrokerContract,\n  request: (accessToken: string) => Promise<T>\n) {\n  const token = await broker.getValidAccessToken();\n  if (!token) throw new AuthSessionError('AUTH_SESSION_EMPTY', false);\n  try {\n    return await request(token);\n  } catch (error) {\n    const classified = classifyAuthError(error);\n    if (classified.code !== 'ACCESS_TOKEN_EXPIRED') throw classified;\n    const pair = await broker.refresh('access-token-expired');\n    return await request(pair.accessToken);\n  }\n}\n\nexport function createRealtimeAuthAdapter(broker: AuthTokenBrokerContract) {\n  return {\n    getAccessToken: () => broker.getValidAccessToken(120_000),\n    recover: async (error: unknown) => {\n      const classified = classifyAuthError(error);\n      if (classified.code !== 'ACCESS_TOKEN_EXPIRED') throw classified;\n      return (await broker.refresh('realtime-access-token-expired'))\n        .accessToken;","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/common/auth/src/token-broker.ts#L391-L427","documentation":"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.","triggerScenarios":"Thrown at packages/common/auth/src/token-broker.ts:409 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Sign in again; the stored auth session is empty or was cleared.","Check that session storage (cookies/keychain) is available and not blocked.","Restart the app if the session state is corrupted."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}