{"record":{"id":"42d750308c89c159","repo":"toeverything/AFFiNE","slug":"auth-operation-cancelled","errorCode":"AUTH_OPERATION_CANCELLED","errorMessage":"AUTH_OPERATION_CANCELLED","messagePattern":"AUTH_OPERATION_CANCELLED","errorType":"error_code","errorClass":"AuthSessionError","httpStatus":null,"severity":"error","filePath":"packages/common/auth/src/token-broker.ts","lineNumber":297,"sourceCode":"          status: 'offline-authenticated',\n          session: this.toSnapshot(current),\n          code: classified.code,\n        });\n      }\n      throw classified;\n    }\n  }\n\n  private async persistPending() {\n    const pending = this.pending;\n    if (!pending) throw new AuthSessionError('AUTH_SESSION_EMPTY', false);\n    try {\n      await this.mutateStorage(() => this.storage.save(pending.pair));\n    } catch {\n      throw new AuthSessionError('AUTH_TOKEN_STORAGE_UNAVAILABLE', true);\n    }\n    if (pending.epoch !== this.mutationEpoch) {\n      throw new AuthSessionError('AUTH_OPERATION_CANCELLED', true);\n    }\n    this.pending = null;\n    this.pair = pending.pair;\n    this.publish({\n      status: 'authenticated',\n      session: this.toSnapshot(pending.pair),\n    });\n    return pending.pair;\n  }\n\n  private async mutateStorage<T>(operation: () => Promise<T>) {\n    const result = this.storageMutation.then(operation, operation);\n    this.storageMutation = result.then(\n      () => {},\n      () => {}\n    );\n    return await result;\n  }","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/common/auth/src/token-broker.ts#L279-L315","documentation":"persistPending aborts with AuthSessionError('AUTH_OPERATION_CANCELLED') when the storage mutation completed but the pending epoch no longer matches the broker's current epoch, meaning a newer auth operation superseded this one and its result must be discarded.","triggerScenarios":"Thrown at packages/common/auth/src/token-broker.ts:297 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the sign-in flow; the previous attempt was cancelled before completion.","Do not close the authentication window or navigate away during the flow.","If the user intentionally cancelled, no action is needed."],"exampleFix":null,"handlingStrategy":"try-catch","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"}