πDoing Something Only When a New Session is Created
import { createOidc } from "oidc-spa";
const oidc = await createOidc({ /* ... */ });
if (oidc.isUserLoggedIn && oidc.isAuthMethod === "back from auth server") {
// Do something related to initialization or clearing cache
}import { createReactOidc } from "oidc-spa/react";
export const {
/* ... */
getOidc
} = createReactOidc({ /* ... */ });
getOidc().then(oidc => {
if( !oidc.isUserLoggedIn ){
return;
}
if( oidc.authMethod === "back from auth server" ){
// Do something related to initialization or clearing cache
}
});import { useOidc } from "./oidc";
import { useEffect } from "react";
function MyComponent(){
const { isUserLoggedIn, authMethod } = useOidc();
useEffect(()=> {
// Warning! In dev mode, when React Strict Mode is enabled
// this will be called twice!
if( !isUserLoggedIn ){
return;
}
if( authMethod === "back from auth server" ){
// Do something related to initialization or clearing cache
}
}, []);
}Last updated
Was this helpful?