toeverything/AFFiNE · error · Error

Missing native auth exchange code.

Error message

Missing native auth exchange code.

What it means

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.

Source

Thrown at packages/frontend/apps/electron/src/main/auth/handlers.ts:98

      authCookieNames.map(name =>
        authSession.cookies
          .remove(endpoint, name)
          .catch(error =>
            logger.debug(
              'failed to clear native auth cookie',
              endpoint,
              name,
              error
            )
          )
      )
    )
  );
}

async function exchangeSession(endpoint: string, response: SignInResponse) {
  if (!response.exchangeCode) {
    throw new Error('Missing native auth exchange code.');
  }

  const exchangeResponse = await fetchAuth(
    endpoint,
    '/api/auth/session/exchange',
    {
      code: response.exchangeCode,
      installationId: await getInstallationId(),
      platform: 'electron',
      deviceName: os.hostname(),
    }
  );
  const body = await readJson<AuthTokenResponse>(exchangeResponse);
  const { persistent } = await setAuthSession(endpoint, body);
  await clearAuthCookies(endpoint);
  return { persistent };
}

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Restart the sign-in flow; the exchange code was lost between the browser and the app.
  2. Ensure the app is registered as the handler for the auth callback URL.
  3. Do not modify or reopen the callback URL manually.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/frontend/apps/electron/src/main/auth/handlers.ts:98 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/c4c7b0801b4f624c. Report an issue: GitHub.