Home / Developers / Quickstarts / TypeScript
Quickstart: TypeScript
Verify the sign-in token, handle back-channel logout, and verify then handle lifecycle webhooks with @authvertex/sdk and @authvertex/events. Node.js 24 or newer.
Install
Coming — available at release. When the packages are released, you will install them with:
npm install @authvertex/sdk @authvertex/events@authvertex/sdk verifies what your application receives: ID and access tokens, back-channel logout tokens and webhook signatures. @authvertex/events turns a verified webhook body into a typed event. Both are ESM-only, have no runtime dependencies and need Node.js 24 or newer; they use only WebCrypto and the Fetch API.
Sign-in itself is standard OpenID Connect: any OIDC client library performs the authorization code flow with PKCE. The SDK checks the tokens you get back.
Configure
Read the issuer and your client ID from your application settings. The examples read them from environment variables.
// lib/authvertex.ts (server-only)
import { LogoutVerifier, RemoteJWKS, TokenVerifier, discoverJwksUri } from "@authvertex/sdk";
const issuer = process.env.AUTHVERTEX_ISSUER!;
const clientId = process.env.AUTHVERTEX_CLIENT_ID!;
// The issuer's signing keys, found through OIDC discovery. Cached, and refreshed when a token names a new key.
export const keys = new RemoteJWKS({ url: await discoverJwksUri(issuer) });
export const tokens = new TokenVerifier({ issuer, audience: clientId, keys });
export const logoutVerifier = new LogoutVerifier({ issuer, audience: clientId, keys });Verify the sign-in token
After your OIDC client library has exchanged the authorization code at the token endpoint, verify the ID token with the nonce you sent:
import { tokens } from "@/lib/authvertex";
const id = await tokens.verifyIdToken(idToken, { nonce: expectedNonce });
// id.subject: the stable user ID. Never an email.
// id.tenantId: your own tenant ID for the organization, as you set it when you created the organization.
// id.orgId and id.membershipEpoch: keep the highest membershipEpoch seen per (subject, orgId); a lower one is stale.
// epochs is your own store: recordHighest saves the value and returns false when a higher one is already stored.
if (!(await epochs.recordHighest(id.subject, id.orgId, id.membershipEpoch))) {
throw new Error("stale membership: sign in again"); // fail closed: do not create the session
}
await sessions.create({ userId: id.subject, tenantId: id.tenantId, sessionId: id.sessionId });verifyIdToken checks the signature, iss, aud, azp, exp, nbf and iat with a 60-second clock skew, the nonce, and the organization claims. Any failure throws an AuthVertexError; nothing returns a bare boolean. A verified token proves who the user is. What the user may do in your product is your own decision.

Back-channel logout
When a session ends, AuthVertex posts a signed logout token to the backchannel_logout_uri of your client. The handler verifies it, never processes the same token twice, and calls you:
// app/auth/backchannel-logout/route.ts (a Fetch API route handler)
import { createLogoutHandler } from "@authvertex/sdk";
import { logoutVerifier } from "@/lib/authvertex";
export const POST = createLogoutHandler({
verifier: logoutVerifier,
// End every local session with this session ID, or every session of the subject when it has none.
onLogout: async (t) => {
await sessions.end({ sessionId: t.sessionId, userId: t.subject });
},
});The handler answers 200 after onLogout returns, and 400 when the token is invalid, always with Cache-Control: no-store. If onLogout throws, the token is released so the retry is accepted. A token you already processed is answered 200 without calling you again (AuthVertex is retrying after a lost 200); while its first delivery is still running, a repeat gets 503 with Retry-After. The replay cache is per process: with several instances, give the LogoutVerifier a shared replay cache (ReplayCache).
Webhooks: verify, then parse
Webhook endpoints are signed with scheme v2 by default: AuthVertex signs each delivery and you verify it with AuthVertex's published public keys, so you hold no shared secret. The signature is bound to your endpoint ID, which you receive when you register the endpoint.
// app/webhooks/authvertex/route.ts
import { createWebhookHandler, webhookKeysFromJWKS } from "@authvertex/sdk";
import { EventParseError, parseLifecycleEvent, type LifecycleEvent } from "@authvertex/events";
// AuthVertex's webhook signing keys. Old and new keys overlap during a rotation: reload them at most every five minutes.
const signingKeys = await (await fetch(`${process.env.AUTHVERTEX_API_URL}/v1/webhook-signing-keys`)).json();
export const POST = createWebhookHandler({
ed25519Keys: webhookKeysFromJWKS(signingKeys),
endpointId: process.env.AUTHVERTEX_WEBHOOK_ENDPOINT_ID!,
requireV2: true, // refuse deliveries without a v2 signature
onEvent: async (verified) => {
// The signature, timestamp window and event ID were checked; duplicates never reach this point.
let event: LifecycleEvent;
try {
event = parseLifecycleEvent(verified.raw);
} catch (e) {
if (e instanceof EventParseError && e.code === "unknown_event_type") return; // a newer type: acknowledge, ignore
throw e; // answers 500, so AuthVertex retries
}
if (event.application_id !== process.env.AUTHVERTEX_APPLICATION_ID) return;
switch (event.type) {
case "membership.suspended":
case "membership.deprovisioned":
case "session.revoked":
await sessions.endAllForMembership(event.membership_id);
break;
case "membership.updated":
if (event.changed.includes("roles")) await roles.refresh(event.membership_id); // role values are never sent
break;
default:
break; // the other types: see the event catalog
}
},
});The handler answers 401 for a bad signature, 400 for a malformed body, 200 for a duplicate (your onEvent is not called twice) and 500 when onEvent throws. Return only once the change is stored: AuthVertex retries anything but a 2xx. Read the raw body: do not put a body parser in front of the handler. The deduplication cache is per process; with several instances, pass a shared dedupe cache.
After you have enforced a suspension, deprovisioning or session revocation, report it with Acknowledge revocation, using the event's revocation_id.
Endpoints that keep a shared secret (scheme v1 or v1+v2) pass keys: { [kid]: secret } instead of, or next to, ed25519Keys. For frameworks without Fetch API handlers, toNodeHandler(handler) adapts both handlers to Express and node:http; mount them before any body parser.

Errors
Every verification failure throws AuthVertexError with a stable code, the same in every AuthVertex SDK. keys_unavailable means the issuer's keys could not be fetched: treat it as a temporary failure, never as success. See Error codes.
Next steps
- Run the flow end to end in the sandbox.
- Test your logout and webhook endpoints with the conformance kit.
- The integration guide covers client registration, claims and webhooks in full.