go-auth
GuidesClient

OAuth linking

oauthApi — link, unlink, and list connected OAuth providers on an existing account, built on the apiRequest helper.

OAuth linking client

Wraps every endpoint from the OAuth linking guide into oauthApi, built on the apiRequest helper.

// lib/api/oauth.ts
import { apiRequest } from "./client";

const API_BASE = "/api";

export const oauthApi = {
  link: async (provider: string) => {
    const { url } = await apiRequest(API_BASE, "POST", `/auth/oauth/${provider}/link`);
    window.location.href = url;
  },

  unlink: (provider: string) =>
    apiRequest(API_BASE, "POST", `/auth/oauth/${provider}/unlink`),

  listConnected: () => apiRequest(API_BASE, "GET", "/auth/oauth/providers"),
};

For admin sign-in, handle step=two_factor on the /auth/callback landing page before refreshing the logged-in user. Read challengeId and expiresAt, show the existing 2FA form, and post { challengeId, code } to /auth/2fa/verify using apiRequest and the same cookie jar. The callback sets the HttpOnly binding cookie; session cookies are issued only after verification.

// Settings page — "Connect GitHub" button
<button onClick={() => oauthApi.link("github")}>Connect GitHub</button>
try {
  await oauthApi.unlink("github");
} catch (err) {
  if (err.error === "cannot_unlink_last_provider") {
    // prompt the user to set a password first — see the Security client
  }
}

List connected providers

const { providers } = await oauthApi.listConnected();
// providers.map(p => p.provider) — e.g. ["github", "google"]

Next

  • Setup — the apiRequest helper this is built on
  • OAuth linking — full request/response/error reference
  • Security client — setting a password before unlinking the last provider

On this page