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"),
};Link provider
// Settings page — "Connect GitHub" button
<button onClick={() => oauthApi.link("github")}>Connect GitHub</button>Unlink provider
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
apiRequesthelper this is built on - OAuth linking — full request/response/error reference
- Security client — setting a password before unlinking the last provider