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

Quickstart

Add Google and GitHub login with a backend router and simple frontend SDK helpers.

1. Create your project

Create an AnyOAuth project, enable Google and GitHub, and register http://localhost:3000/auth/callback. Save the client ID and client secret in your backend environment. You do not need your own Google or GitHub app.

Use the current SDK source for the helpers below. The published 0.1.0 packages predate these methods.

2. Mount your backend router

Choose your backend language or Node.js server below. Configure AnyOAuth with your project credentials and register your app’s exact /auth/callback URL:

Your backend

Mount in your existing Express app.

import { createAuth } from "@anyoauth/node/express";

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

app.use("/auth", auth.router());

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

Node.js tabs cover Express, Hono, Fastify, Next.js, Astro and plain HTTP. The managed router handles login, callbacks, profile retrieval and session cookies for you. Use your app’s public origin in its configuration.

During /auth/callback, the managed SDK completes login, retrieves the verified profile, creates the authenticated session, and redirects to / (or your configured returnTo). You do not need to add a separate profile-fetch call to this router. If your backend needs to find or create a user at that point, use the onLogin(profile, request) hook.

The other tabs show Flask, Gin, Laravel, Spring Boot, Rails, ASP.NET Core, Axum and Phoenix routes using their language’s SDK. Each example mounts login, callback, profile and logout endpoints in your existing application. Configure the framework’s session middleware as described above its sample; the SDK verifies the login and your framework stores the application session.

3. Add your login buttons

Call anyoauth.startLogin('google') or anyoauth.startLogin('github') from a button. Choose your frontend in the tabs; no client secret belongs here:

Your login button
import * as anyoauth from '@anyoauth/client';

export default function Login() {
return <button onClick={() => anyoauth.startLogin('google')}>
Sign in with Google
</button>;
}

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

startLogin() navigates away from your page. The user signs in through AnyOAuth, then your backend handles the callback and redirects back to your app. Read the profile after that return, when your frontend loads again.

4. Show the profile

Call getProfile() when your page or component mounts. It reads the existing authenticated session through your backend’s /auth/profile route:

  • Before login: it returns null; show your login buttons.
  • After the successful callback and redirect: it returns the profile; show your signed-in UI.
  • If the request fails: show a loading error rather than treating it as signed out.

Yes, if (!profile) is the check for choosing the signed-out UI. Each example below waits for that check to finish before showing the login buttons:

Check the session and show the profile
import { useEffect, useState } from 'react';
import * as anyoauth from '@anyoauth/client';

export default function Profile() {
const [profile, setProfile] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState('');

// Runs on page load, including after the sign-in redirect.
useEffect(() => {
anyoauth.getProfile()
.then(setProfile)
.catch(() => setError('Could not load your session.'))
.finally(() => setLoading(false));
}, []);

if (loading) return <p>Loading your session…</p>;
if (error) return <p role="alert">{error}</p>;
if (!profile) return <>
<button onClick={() => anyoauth.startLogin('google')}>Sign in with Google</button>
<button onClick={() => anyoauth.startLogin('github')}>Sign in with GitHub</button>
</>;

return <p>Signed in as {profile.name ?? profile.username ?? profile.subject}</p>;
}

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

Use profile.subject as the stable user ID; names and emails may be null.

Serve the frontend and /auth on the same origin, or use a development proxy. For plain HTML, bundle the browser SDK.

Optional customization

The basic sign-in flow is complete. The following examples are optional, for apps that need protected backend routes, database integration or custom session handling.

Read the profile on your backend

If you add your own protected backend routes, read the authenticated session before serving their resources. Your frontend check controls what your UI displays; it does not replace the session check on a protected backend route. Choose your language and server in the tabs below. Node.js uses auth.getProfile(request); the other frameworks read the verified profile saved by their callback handler in step 2:

Read the authenticated profile on your backend

Use the configured auth instance from step 2 to protect your own application route. For Next.js and Astro, move that configuration into a shared server module.

// Use the auth instance configured in step 2.
app.get('/account', async (req, res) => {
const profile = await auth.getProfile(req);
if (!profile) return res.sendStatus(401);

res.setHeader('Cache-Control', 'no-store');
res.json(profile);
});

npm install @anyoauth/nodeAuthenticated backend sessionCurrent source example · published 0.1.0 predates these helpers

Save profiles to your database

If your app stores user records, the managed Node.js flow’s onLogin hook receives the verified profile before the authenticated session is created:

JS
const auth = createAuth({
...config,
onLogin: async (profile) => {
await users.upsert(profile.subject, profile);
},
});

Here config is your backend configuration from step 2, and users is your application’s database service. Use profile.subject to find or create the user. With Flask, Gin, Laravel and the other backend frameworks, save the profile in your callback after completeLogin returns succeeded and before establishing the session.

Customize sessions and routing

  • Use your existing sessions: supply the managed SDK’s session adapter, or keep your framework’s session store.
  • Change paths and redirects: configure authPath, returnTo and sessionMaxAge in the managed router; keep the callback registered exactly.
  • Own the routes: use startLogin and completeLogin directly when you need more control over the callback or storage.

See the Custom integration guide for database hooks, session adapters and custom routes.