cypress: Nuxt: Login through auth0 doesn't redirect to localhost

Current behavior

I created a simple test that checks if the home page redirects to a specific route:

describe('Open Artwork page', () => {
  it('should display the title', () => {
    cy.visit('http://localhost:3000/')
    cy.contains('Artwork').should('be.visible');
  });
});

The user has to login in with Auth0 to access the home page. This is the login command:

Cypress.Commands.add('login', () => {
  const environment = Cypress.env("ENV")
  const tenantName = environment === 'development'
    ? 'artbeat-venture'
    : `artbeat-venture-${environment}`

  const args = {
    email: Cypress.env()[environment]['username'],
    password: Cypress.env()[environment]['password'],
    environment,
    tenantName,
  }

  cy.session(args, () => {
    const { tenantName } = args

    cy.origin(
      `https://${tenantName}.eu.auth0.com`, { args },
      ({ email, password, environment, tenantName, baseUrl }) => {
        cy.visit({
          url: `https://${tenantName}.eu.auth0.com/authorize`,
          qs: {
            client_id: Cypress.env()[environment]['clientId'],
            response_type: "token",
            redirect_uri: `http://localhost:3000`,
          },
        })
        cy.get('#username').type(email)
        cy.get('#password').type(password)
        cy.get('button').contains('Continue').click();
      })
    // assert we've returned to the site
    cy.url().should('contain', '/artwork') // todo: check this
  })
})

We run the login command on the beforeEach:

beforeEach(function () {
  cy.login()
})

We are able to run the test locally with the standard npm run dev (vue app). Screenshot 2022-08-16 at 13 44 55

The github action pipeline is the following and we are not able to run the tests. It looks like after the login cypress cannot redirect to localhost:3000. This is our yml file:

 cypress-run:
    name: Run E2E tests
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup node
        uses: actions/setup-node@v2
        with:
          node-version: 14

      - name: Cypress run
        uses: cypress-io/github-action@v4
        with:
          cache-key: hash-${{ hashFiles('package-lock.json') }}
          build: npm run build
          start: npm run start
          wait-on: http://localhost:3000
          command: npm run cypress-run:staging

      - name: Archive e2e artifacts
        id: artifacts
        uses: actions/upload-artifact@v2
        if: failure()
        with:
          name: e2e
          path: |
            cypress/videos/
            cypress/screenshots/

The test is stuck with a blank page, even with longer timeout (30 mins): should display the title -- before each hook (failed)

I also tried locally with the same github action setup aka:

npm run build
npm run start
npm run cypress-run:staging

and it works.

We checked the logs from auth0 and we receive a successful Login Confirmation message from the logs so I assume the issue is on a cypress level. Maybe it’s a chrome configuration on github.

Thanks in advance!

Desired behavior

The desired behavior is that the app is able to load the homepage after the auth0 redirect on localhost:3000

Test code to reproduce

I can’t provide a repository as my app login is bounded through an auth0 clientId

Cypress Version

10.4.0

Node version

v14.19.1

Operating System

macOS 12.2.1 locally, ubuntu on github

Debug Logs

No response

Other

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

@nicoladl Great! Thanks for clarifying.

It is definitely an issue with the nuxt build. I’m just leaving a message to posterity.

@nicoladl That is great you were able to get this working! I am going to go ahead and close this.

Hello @rachelruderman thanks for checking the logs! This is the log from Auth0:

{
  "date": "2022-08-20T07:04:12.219Z",
  "type": "s",
  "connection": "Username-Password-Authentication",
  "connection_id": "con_PorJdCsqVVywdpvU",
  "client_id": "nlQFbGl8rNXEwPIkzZVHdZ8BuJ1i57U6",
  "client_name": "E2E",
  "ip": "20.114.112.220",
  "user_agent": "Chrome 104.0.5112 / Linux 0.0.0",
  "details": {
    "prompts": [
      {
        "name": "prompt-authenticate",
        "completedAt": 1660979051489,
        "connection": "Username-Password-Authentication",
        "connection_id": "con_PorJdCsqVVywdpvU",
        "strategy": "auth0",
        "identity": "62fde2e4afa2b754ed95e6c2",
        "stats": {
          "loginsCount": 24
        },
        "elapsedTime": null
      },
      {
        "name": "login",
        "flow": "universal-login",
        "initiatedAt": 1660979048860,
        "completedAt": 1660979051535,
        "user_id": "auth0|62fde2e4afa2b754ed95e6c2",
        "user_name": "e2e_user@arcual.art",
        "timers": {
          "rules": 118
        },
        "elapsedTime": 2675
      }
    ],
    "initiatedAt": 1660979048849,
    "completedAt": 1660979052218,
    "elapsedTime": 3369,
    "session_id": "yFaq6d4o7uBrezdwSEJZDIJkR5vBDjU_",
    "stats": {
      "loginsCount": 24
    }
  },
  "hostname": "artbeat-venture-staging.eu.auth0.com",
  "user_id": "auth0|62fde2e4afa2b754ed95e6c2",
  "user_name": "e2e_user@arcual.art",
  "strategy": "auth0",
  "strategy_type": "database",
  "log_id": "90020220820070416198072036425230084824191920799842566226",
  "_id": "90020220820070416198072036425230084824191920799842566226",
  "isMobile": false,
  "id": "90020220820070416198072036425230084824191920799842566226",
  "description": "Successful login"
}

The user agent confirms that is the login from github: "user_agent": "Chrome 104.0.5112 / Linux 0.0.0"

We run our pipeline on Ubuntu: runs-on: ubuntu-latest

It’s weird that the authorize URL is empty. From the command code (see first comment) we compose the URL with a hardcoded part and a variable: https://${tenantName}.eu.auth0.com/authorize So if the tenantName is empty or wrong I would expect something like:

https://.eu.auth0.com/authorize
https://underfined.eu.auth0.com/authorize

Thanks in advance!