Framework Agnostic Adapter

Let's get your App authenticated!

oidc-spa is framework-agnostic, but it’s also client-centric.

It integrates seamlessly with any Single Page Application, but not with full-stack frameworks that rely on server-side rendering (like Next.js).

The only full-stack framework currently supported is TanStack Start, which aligns with oidc-spa’s client-first, server capable architecture.

Note that if you’re using React but not TanStack or React Router, you’ll likely still benefit more from oidc-spa/react-spa than from oidc-spa/core.

In that case, follow the React Router integration guide in Declarative Mode, it should be easy to adapt to your setup.

Installation

npm install oidc-spa

To protect tokens against supply-chain attacks and XSS, oidc-spa must run some initialization code before any other JavaScript in your app.

This design provides much stronger security guarantees than any other adapter, and it also delivers unmatched login performance. More details here.

In Vite apps, this is done through a Vite Plugin (If you'd rather avoid using the Vite plugin checkout the Other SPAs tab).

vite.config.ts
import { defineConfig } from "vite";
import { oidcSpa } from "oidc-spa/vite-plugin";

export default defineConfig({
    plugins: [
        // ...
        oidcSpa()
    ]
});

Basic Usage

Mock Adapter

For certain use cases, you may want a mock adapter to simulate user authentication without involving an actual authentication server.

This approach is useful when building an app where user authentication is a feature but not a requirement. It also proves beneficial for running tests or in Storybook environments.

Creating an API server

Now that authentication is handled, there’s one last piece of the puzzle: your resource server, the backend your app will communicate with.

This can be any type of service: a REST API, tRPC server, or WebSocket endpoint, as long as it can validate access tokens issued by your IdP.

If you’re building it in JavaScript or TypeScript (for example, using Express), oidc-spa provides ready-to-use utilities to decode and validate access tokens on the server side.

You’ll find the full documentation here:

Creating an API Server

Last updated

Was this helpful?