Skip to content

withAuthenticationRequired does not attempt silent token renewal before redirecting to login #1536

@obrassard

Description

@obrassard

Hello,

We are using withAuthenticationRequired to protect most of the routes in our React applications. We’ve noticed that when a previously authenticated user returns to the app with an expired access token, they are always redirected to the IDP login page, even though a valid refresh token is still available in their local storage.

It seems this behavior is intentional, as the current implementation in withAuthenticationRequired.tsx does not attempt to silently renew the access token before calling signinRedirect.

I would expect the library to try renewing the access token using the refresh token (if available) before prompting the user to log in again explicitly.

Is there a way to achieve this behavior with the current implementation ? If not, could we add an optional prop to withAuthenticationRequired that enables attempting signinSilent before calling signinRedirect?

For reference, this is our current configuration :

const config: AuthProviderProps = {
    authority: import.meta.env.VITE_COGNITO_AUTHORITY,
    client_id: import.meta.env.VITE_COGNITO_CLIENT_ID,
    redirect_uri: import.meta.env.VITE_COGNITO_CALLBACK_URL,
    automaticSilentRenew: true,
    response_type: 'code',
    scope: 'email openid profile',
    userStore: new WebStorageStateStore({ store: window.localStorage }),
    extraQueryParams: {
      lang: getCurrentLanguagePreference(),
    },
    onSigninCallback: () => {
      ...
    },
  };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions