{"record":{"id":"3929112fd0b7a0ef","repo":"toeverything/AFFiNE","slug":"auth-token-response-invalid","errorCode":"AUTH_TOKEN_RESPONSE_INVALID","errorMessage":"AUTH_TOKEN_RESPONSE_INVALID","messagePattern":"AUTH_TOKEN_RESPONSE_INVALID","errorType":"error_code","errorClass":"AuthSessionError","httpStatus":null,"severity":"error","filePath":"packages/common/auth/src/token-broker.ts","lineNumber":338,"sourceCode":"        return await this.transport.refresh(refreshToken);\n      } catch (error) {\n        const classified = classifyAuthError(error);\n        const delay = this.retryDelays[attempt];\n        if (!classified.transient || delay === undefined) throw classified;\n        await this.sleep(delay * (0.75 + this.random() * 0.5));\n      }\n    }\n  }\n\n  private toPair(response: AuthTokenResponse): AuthTokenPair {\n    const accessExpiresAt = this.now() + response.expiresIn * 1000;\n    if (\n      !Number.isFinite(response.expiresIn) ||\n      response.expiresIn <= 0 ||\n      !Number.isFinite(accessExpiresAt) ||\n      Math.abs(accessExpiresAt) > 8.64e15\n    ) {\n      throw new AuthSessionError('AUTH_TOKEN_RESPONSE_INVALID', true);\n    }\n    const pair: AuthTokenPair = {\n      version: 1,\n      tokenType: response.tokenType,\n      accessToken: response.accessToken,\n      accessExpiresAt: new Date(accessExpiresAt).toISOString(),\n      refreshToken: response.refreshToken,\n      refreshExpiresAt: response.refreshExpiresAt,\n      session: response.session,\n    };\n    if (!isAuthTokenPair(pair)) {\n      throw new AuthSessionError('AUTH_TOKEN_RESPONSE_INVALID', true);\n    }\n    return pair;\n  }\n\n  private toSnapshot(pair: AuthTokenPair): AuthSessionSnapshot {\n    return {","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/common/auth/src/token-broker.ts#L320-L356","documentation":"toPair validates the refresh response and throws AUTH_TOKEN_RESPONSE_INVALID when expiresIn is not a positive finite number, so a malformed token response from the server never becomes a stored session.","triggerScenarios":"Thrown at packages/common/auth/src/token-broker.ts:338 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the authentication flow; the token endpoint returned a malformed response.","Check the auth server or proxy for modifications to the token response.","Verify the client_id and token endpoint configuration match the auth server."],"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"}