{"record":{"id":"c4c7b0801b4f624c","repo":"toeverything/AFFiNE","slug":"missing-native-auth-exchange-code","errorCode":null,"errorMessage":"Missing native auth exchange code.","messagePattern":"Missing native auth exchange code\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/frontend/apps/electron/src/main/auth/handlers.ts","lineNumber":98,"sourceCode":"      authCookieNames.map(name =>\n        authSession.cookies\n          .remove(endpoint, name)\n          .catch(error =>\n            logger.debug(\n              'failed to clear native auth cookie',\n              endpoint,\n              name,\n              error\n            )\n          )\n      )\n    )\n  );\n}\n\nasync function exchangeSession(endpoint: string, response: SignInResponse) {\n  if (!response.exchangeCode) {\n    throw new Error('Missing native auth exchange code.');\n  }\n\n  const exchangeResponse = await fetchAuth(\n    endpoint,\n    '/api/auth/session/exchange',\n    {\n      code: response.exchangeCode,\n      installationId: await getInstallationId(),\n      platform: 'electron',\n      deviceName: os.hostname(),\n    }\n  );\n  const body = await readJson<AuthTokenResponse>(exchangeResponse);\n  const { persistent } = await setAuthSession(endpoint, body);\n  await clearAuthCookies(endpoint);\n  return { persistent };\n}\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/frontend/apps/electron/src/main/auth/handlers.ts#L80-L116","documentation":"exchangeSession throws when the sign-in response carries no exchangeCode, meaning the web sign-in flow completed without the data needed to exchange cookies for native tokens, so the native session cannot be established.","triggerScenarios":"Thrown at packages/frontend/apps/electron/src/main/auth/handlers.ts:98 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Restart the sign-in flow; the exchange code was lost between the browser and the app.","Ensure the app is registered as the handler for the auth callback URL.","Do not modify or reopen the callback URL manually."],"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"}