OIDC SPA
GitHubHome
v6
  • Documentation
  • Release Notes & Upgrade Instructions
v6
  • Installation
  • Basic Usage
  • Web API
  • Auto Login
  • Auto Logout
  • Error Management
  • Mock
  • User Account Management
  • User Session Initialization
  • Tokens Renewal
  • Setup Guides
    • React Router
    • TanStack Router
    • Full-Stack with Node REST API
  • Providers Configuration
    • Keycloak
    • Auth0
    • Microsoft Entra ID
    • Google OAuth 2.0
    • Other OIDC Provider
  • Resources
    • Why No Client Secret?
    • End of third-party cookies
    • JWT Of the Access Token
    • Discord Server
  • User Impersonation
  • Sponsors
Powered by GitBook
On this page
  • Add the lib to your dependencies
  • Editing your App entrypoint

Was this helpful?

Export as PDF

Installation

NextBasic Usage

Last updated 14 days ago

Was this helpful?

Before starting be aware that oidc-spa is not suited for Next.js.

If you are using Next the closer alternative is to use (with if you are using Keycloak). See .

If you're having issues don't hesitate to !

Add the lib to your dependencies

npm install oidc-spa
yarn add oidc-spa
pnpm add oidc-spa
bun add oidc-spa

Editing your App entrypoint

This is optional but recommended for better performances and security.

First rename your entry point file from main.tsx (or main.ts) to main.lazy.tsx

mv src/main.tsx src/main.lazy.tsx

The create a new main.tsx file:

src/main.tsx
import { oidcEarlyInit } from "oidc-spa/entrypoint";

const { shouldLoadApp } = oidcEarlyInit({
    freezeFetch: true,
    freezeXMLHttpRequest: true
});

if (shouldLoadApp) {
    import("./main.lazy");
}

Comming soon, .

You can skip this for now. It will be explained in the dedicated setup guide:

First rename your entry point file from main.tsx (or main.ts) to main.lazy.tsx

mv src/index.tsx src/index.lazy.tsx

The create a new index.tsx file:

src/index.tsx
import { oidcEarlyInit } from "oidc-spa/entrypoint";

const { shouldLoadApp } = oidcEarlyInit({
    freezeFetch: true,
    freezeXMLHttpRequest: true
});

if (shouldLoadApp) {
    import("./index.lazy");
}
NextAuth.js
the Keycloak adapter
this guide
reach out on Discord
follow progress
React Router