How to authenticate using Cypress and @auth0/auth0-react

There seems to be a misalignment in the docs on Cypress on how to set up authentication using the oauth/token endpoint.

Their official documentation produces a local storage key value pair that looks like the below.

const item = {
        body: {
          decodedToken: {
            claims,
            user: { ... },
            audience,
            client_id,
          },
        },
        expiresAt: exp,
      }

      window.localStorage.setItem('auth0Cypress', JSON.stringify(item))

However the one created by the Auth0 React package produces something similar to:

const item = {
      body: {
        access_token,
        audience,
        client_id,
        decodedToken: {
          claims,
          user: { ... },
          encoded,
          header
        },
        expires_in,
        id_token,
        scope,
        token_type
      },
      expiresAt: exp
    }

    window.localStorage.setItem(`@@auth0spajs@@::${client_id}::${audience}::${scope}`, JSON.stringify(item))

I am able to get the https://${auth)_domain}/oauth/token request working, however am not able to work out how to get the right data off the response for it to fit the data structure the Auth0 react SDK wants it in.

1 Like

I’d imagine this would actually extend any anyone that is using the Auth0 React SDK and trying to save the auth session to local storage.

I have created a stack overflow post with more information - javascript - Auth0 authentication with Cypress - Stack Overflow

1 Like