Unispec ID
Quickstart
Working sign-in with @unispec-ai/id in under 15 minutes.
1. Install
npm install @unispec-ai/id2. Proxy the ID API from your origin
One rewrite makes the session cookie first-party in every browser:
export default defineConfig({
server: { proxy: { "/v1/id": "https://id.unispec.ai" } },
});async rewrites() {
return [{ source: "/v1/id/:path*", destination: "https://id.unispec.ai/v1/id/:path*" }];
}3. Sign users up and in
import { createIdClient, IdError } from "@unispec-ai/id";
const id = createIdClient({ baseUrl: "/v1/id" });
await id.auth.signUp({ email, password, name });
await id.auth.signIn({ method: "password", email, password });
const stop = id.auth.onAuthStateChanged(({ session }) => {
render(session ? `Hi ${session.identity.email}` : "Signed out");
});
await id.auth.signOut();Errors carry stable codes:
try {
await id.auth.signIn({ method: "password", email, password });
} catch (err) {
if (err instanceof IdError && err.code === "invalid_credentials") show("Wrong email or password");
if (err instanceof IdError && err.code === "session_aal2_required") askForTotpCode();
}4. Google sign-in
await id.auth.signInWithGoogle({ returnTo: window.location.href });
// Redirect round-trip; onAuthStateChanged fires when the user lands back.5. Second factors
// TOTP: show the QR (or secret), then confirm one code.
const enrollment = await id.settings.enableTotp();
await id.settings.verifyTotp(codeFromApp, enrollment);
// Future sign-ins: pass totpCode to complete the aal2 step-up in one call.
await id.auth.signIn({ method: "password", email, password, totpCode });
// Passkeys (see the origin note on the product page):
await id.settings.addPasskey();
await id.auth.signIn({ method: "passkey" });6. Verify sessions on your server
const id = createIdClient(); // UNISPEC_ID_URL or https://id.unispec.ai
const session = await id.verifySession({ token: req.headers["x-session-token"] });
// or, for forwarded browser requests: { cookie: req.headers.cookie }
if (!session) return res.status(401).end();That's the whole surface. A complete runnable UI (password + Google +
passkeys + TOTP) lives in the repo at packages/examples/web/id-react.