Your agent can build the integration.See the two prompts
Documentation navigation

Frontend integrations

React, Vue, Astro, HTML, Svelte, Next.js and Nuxt use the same three browser helpers.

On this page

Mount the quickstart backend router first. Install the current SDK source for these helpers. All examples below use startLogin('google'), getProfile() and logout() against that backend’s /auth routes. There are no frontend secrets or localStorage login credentials. Browser-only OAuth is deferred.

Choose your frontend

Your frontend
import { useEffect, useState } from 'react';
import * as anyoauth from '@anyoauth/client';

export default function Login() {
const [user, setUser] = useState(null);
const [error, setError] = useState('');

useEffect(() => {
anyoauth.getProfile().then(setUser).catch(() => setError('Could not load your session.'));
}, []);

async function signOut() {
try { await anyoauth.logout(); setUser(null); }
catch { setError('Could not sign out.'); }
}

return <section>
{error && <p role="alert">{error}</p>}
{user ? <>
<p>Signed in as {user.name ?? user.username ?? user.subject}</p>
<button onClick={signOut}>Sign out</button>
</> : <>
<button onClick={() => anyoauth.startLogin("google")}>Google</button>
<button onClick={() => anyoauth.startLogin("github")}>GitHub</button>
</>}
</section>;
}

npm install @anyoauth/clientBrowser helpers · uses your backend sessionCurrent source example · published 0.1.0 predates these helpers

React uses an effect, Vue/Nuxt use onMounted, and Svelte uses onMount to read the session after hydration. Next.js needs the shown 'use client' boundary. Astro runs its <script> in the browser; do not call these helpers in server frontmatter.

Use profile.subject as the stable identity. Names, usernames and emails can be null. These examples update the UI after logout only when the backend request succeeds.

Plain HTML

The HTML example imports /auth-client.js, a bundled copy of the browser SDK. After installing the SDK source in your app, build it once:

Terminal
npx esbuild node_modules/@anyoauth/client/index.js --bundle --format=esm --outfile=public/auth-client.js

Serve public/auth-client.js at /auth-client.js alongside the HTML and your backend routes. Plain browsers cannot resolve the npm package’s bare import name without a bundler or import map. The quickstart shows the browser helpers used by every framework.

Same-origin backend and development proxies

The browser helpers expect the auth routes on the frontend’s own origin. For a Vite frontend and a separately listening backend, proxy /auth to that backend. Set the managed router’s origin to the public browser origin, including its development port, and register ${origin}/auth/callback exactly.

If you mount at /api/auth, pass that path to all three helpers:

JS
anyoauth.startLogin('google', '/api/auth');
const profile = await anyoauth.getProfile('/api/auth');
// On the sign-out button: await anyoauth.logout('/api/auth');

Cross-origin auth endpoints are not enabled by these examples. A static frontend can use a same-origin proxy to its backend; it is not a browser-only OAuth integration.

Next.js backend route

Put this in app/auth/[...route]/route.js:

Next.js backend
import { createAuth } from "@anyoauth/node/auth";

const auth = createAuth({
clientId: process.env.ANYOAUTH_CLIENT_ID,
clientSecret: process.env.ANYOAUTH_CLIENT_SECRET,
origin: "http://localhost:3000",
});

// app/auth/[...route]/route.js
export const GET = auth.handle;
export const POST = auth.handle;

npm install @anyoauth/nodeManaged backend routerCurrent source example · published 0.1.0 predates these helpers

Register http://localhost:3000/auth/callback for the local example and configure an HTTPS origin for production. Keep credentials in server environment variables.

Astro backend route

With an Astro server adapter, put this in src/pages/auth/[...route].js:

Astro backend
import { createAuth } from "@anyoauth/node/auth";

const auth = createAuth({
clientId: process.env.ANYOAUTH_CLIENT_ID,
clientSecret: process.env.ANYOAUTH_CLIENT_SECRET,
origin: "http://localhost:3000",
});

// src/pages/auth/[...route].js (Astro with a server adapter)
export const prerender = false;
export const GET = ({ request }) => auth.handle(request);
export const POST = ({ request }) => auth.handle(request);

npm install @anyoauth/nodeManaged backend routerCurrent source example · published 0.1.0 predates these helpers

Change the shown origin and registration to your actual Astro port (commonly 4321). This endpoint needs server execution; a static-only Astro deployment must route /auth to a separate backend. Server environment variables must be configured in that backend.

Existing sessions and protected resources

Browser profiles are for display, not permission checks. Your protected backend routes validate the authenticated SDK session or your own session store. Custom user hooks, sessions and routes remain available.