Playwright testing with Authorization Code Flow

Our team is experiencing some problems with integration testing of our React application in Playwright.

In our app, user authentication is performed though auth0, using the Auth0Provider component from the auth0-react package. It uses the Authorization Code Flow, which means that the generated access token is not exposed on the client side. Authentication API calls return short-lived refresh tokens instead.

During testing with playwright, the auth0 API gets called again and again, to see whether the user is still logged in or not. To avoid Too Many request errors from the Aut0 API when running our tests, we would like our integration tests to not have to make all of these calls. A single authentication call is OK of course.

Mocking the calls is the first thing we tried, but we haven’t yet succeeded. We get no errors to refer to, it simply does not work.

We also tried storing the refresh token locally, but the expiry time is too short, so that the calls are still made regularly. We tried setting a longer expiry time in the Auth0 console, but somehow this does not seem to have any effect.

Does anyone here have an idea how to avoid all of these calls during testing?