Skip to content

Stuck with auth.isLoading = true with previous page action #1243

Open
@ValGab

Description

@ValGab

Hello,

I have a page with several elements and a button that does this action.

<div 
  onClick={() => { auth.signinRedirect({ redirect_uri: window.location.origin + `/path` });  }}               
>

When I click this button, I am redirected to Keycloak to log in. But when I do "Back" with the browser, I'm stuck on my redirect display in my app because auth.isLoading=true and auth.activeNavigator="signinRedirect". I have experienced this problem with Firefox and Edge.

Here is my App.tsx file

const App: React.FC = () => {
  const auth = useAuth();

  switch (auth.activeNavigator) {
    case "signinSilent":
      return (
        <main className="redirect">
          <div>
            <p>Connexion en cours...</p>
            <Loader className="contained" />
          </div>
        </main>
      );
    case "signoutRedirect":
      return (
        <main className="redirect">
          <div>
            <p>Déconnexion en cours...</p>
            <Loader className="contained" />
          </div>
        </main>
      );
  }

  if (auth.isLoading) {
    return (
      <main className="redirect">
        <div>
          <p>Redirection en cours...</p>
          <Loader className="contained" />
        </div>
      </main>
    );
  }

  if (auth.error) {
    return (
      <main className="redirect">
        <div>
          <p>Vous n'êtes plus connecté(e)</p>
          <button
            className="action-btn"
            onClick={() => {
              auth.signinRedirect({ redirect_uri: window.location.href });
            }}
          >
            Se connecter
          </button>
        </div>
      </main>
    );
  }

There is a way to fix it and display my initial page with my button ?

Config :

  • React v18
  • Keycloak

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions