Skip to content

Commit

Permalink
Update react-router example
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Jul 24, 2024
1 parent ac69a8b commit 54701d1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions examples/react-router/src/router/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ async function protectedRouteLoader({ request }: LoaderFunctionArgs) {
const oidc = await prOidc;

if (!oidc.isUserLoggedIn) {
await oidc.login({
doesCurrentHrefRequiresAuth: true,
redirectUrl: request.url
});
// Replace the href without reloading the page.
// This is a way to make oidc-spa know where to redirect the user
// if the authentication process is successful.
history.pushState({}, "", request.url);

// After the successful login the user will be redirected to location.href (here).
// location.href is request.url because we replaced the href above.
await oidc.login({ doesCurrentHrefRequiresAuth: true });

// Never here, the login method redirects the user to the identity provider.
}
Expand Down

0 comments on commit 54701d1

Please sign in to comment.