Cypress Testing with SPA + Custom API (getTokenSilently function not working in Cypress)

Hello all :slight_smile:

Where I’m At

We are working on a project that is a React webapp that uses Auth0 to authenticate users. Also, we have a custom api setup in order to make request to the backend.

The issue

I am running issues with setting up Cypress testing for this project. I finally able to log in as a user by following this github: “https://github.com/dunson062786/login-programmatically-into-auth0-with-cypress”, however i am getting “HTTP error 401 Unauthorized” when I am trying to make request.

I need to make some changes to the auth_audience in order to make the cypress logged in. I am not sure if that is the reason is breaking the getTokenSilently function.

Below are the part that I changed in order for the Cypress stay logged in. I changed the audience to custom API audience instead of default (which is system API). I provide the cypress.env.json and auth_config.json for reference purpose.

When I console log the system browser shows that ‘isAuthenticated’ is true, however the token is undefined.

Thank you for your time reading it, any help will be greatly appreciated! :pray:

I have the same problem. I am searching for a solution but it would be very nice to provide the solution in case you could solve it.

1 Like

I’m struggling to get this to work too (using auth0-spa-js@1.9.0). I seem to be getting a valid token response back from the POST request, and it is setting the relevant cookie and hitting the correct callback route, however the isAuthenticated value from auth0FromHook.isAuthenticated() (in my application’s auth context provider) is coming back as false for some reason. Any ideas as to why that may be?