Test force login with max_age=0 react SDK

Problem statement

We want to test force login with max_age=0 with our react SDK. How to do it?

Solution

  1. Download the following sample we have to test the react SDK: Auth0 React SDK Quickstarts: Add Login to your React App
  2. Add two dropdown buttons in the components/NavBar.js file of the project:
    a. one that forces login with max_age=0
    b. another one without max_age=0
<DropdownItem
id="qsLoginBtn"
color="primary"
block
onClick={() => loginWithRedirect({max_age: 0})}>
<FontAwesomeIcon icon="power-off" className="mr-3" /> Force Login Max_Age=0
</DropdownItem>
<DropdownItem
id="qsLoginBtn"
color="primary"
block
onClick={() => loginWithRedirect({})}>
<FontAwesomeIcon icon="power-off" className="mr-3" /> Force Login without Max Age
</DropdownItem>
</DropdownMenu>
  1. Run the application and sign in, then click on the ForceLogin without the Max Age Button of the dropdown menu. it will hit the authorize endpoint without the max_age=0 parameter and it will not prompt for login, which is expected.
    image

  2. Then, click on the ForceLogin without max_age = 0 and it will successfully prompt for login → which is also expected.
    image

By doing this, you should be able to test how to force login with max_age=0. However, we strongly recommend reading this doc to make sure you are doing the best practices for your application, as this is just for testing the behavior

1 Like