If there is no part of your app that can be accessed without being logged it you can make oidc-spa automatically redirect your users to the login pages when they are not authenticated.
Note that in this mode you don't have to check isUserLoggedIn (you know it's true), or useOidc({ assertUserLoggedIn: true })(you know that's the case).
import { createOidc, OidcInitializationError } from"oidc-spa";try{constoidc=awaitcreateOidc({// ... isAuthGloballyRequired:true,// Optional, the default value is: location.href (here)// postLoginRedirectUrl: "/dashboard"});}catch(error){constoidcInitializationError= error asOidcInitializationError;console.log(oidcInitializationError.message);console.log(oidcInitializationError.type); // "server down" | "bad configuration" | "unknown";}
src/oidc.ts
import { createReactOidc } from"oidc-spa/react";exportconst {OidcProvider,useOidc,prOidc} =createReactOidc({// ... isAuthGloballyRequired:true,// Optional, the default value is: location.href (here)// postLoginRedirectUrl: "/dashboard"});