1
  1. I set up (in my cypress commands):
Cypress.Commands.add("loginByApi1", (username1, password1, TrackingId1) => {
  cy.session([username1, password1, TrackingId1], () => {
    cy.request({
      method: 'POST',
      url: 'https://someWebPage/api/challenge/credentials',
      body: {
        email: username1,
        password: password1,
        TrackingId: TrackingId1
      }
    }).then(({body}) => {
      window.localStorage.setItem('authToken', body.token)
      cy.log(body.token)
    })
  })

This is the endpoint with parameters used for login.

  1. I call in my test
cy.loginByApi1(Cypress.env('mainInvestorUserEmail'), Cypress.env('mainInvestorUserPassword'), 'Cypress.env('trackingID')')
  1. This is the session body (passes successfully it seems - see image) Notice that cy.log(body.token) is empty

See Image

  1. When I try cy.visit('/') in order to visit my base page, URL is still redirected to login screen

  2. In my local storage i have these keys

(See second image)

I tried replacing authToken with accessToken, since this is shown in local storage, but same result.

Not sure if I'm doing it correctly here, but this is on the official cypress site and other sites as well.

I can login using UI so my credentials and approach in that regard are correct.

Briana
  • 204
  • 7
GjoDim
  • 7
  • 2
  • Have you tried just logging `body`? Perhaps you're not getting the 200 response you'd thought, and there is no `token`. – agoff Feb 17 '23 at 14:22
  • How does your front page check if the user is authenticated? How is that decision made to redirect to the login screen? – Michal Trojanowski Feb 17 '23 at 14:39
  • @agoff yes, you can see in my above code that i use `cy.log(body.token)` but it shows as empty but not sure why. If in fact that endpoint returns nothing, i am not sure what i can use to setup my session otherwise? – GjoDim Feb 17 '23 at 21:55
  • @MichalTrojanowski I really am not sure. What i can see when observing the endpoint to which i make the above request to `/api/challenge/credentials` is not returning anything seemingly (when observing through UI). When i execute the same through Postman, i have values in the response.body for the following fields (in order): - signedUrlToken - access_token - jwt - refresh_token - missingAnswers - redirect_url - mfaVerified – GjoDim Feb 17 '23 at 22:17
  • @GjoDim - can you try logging just `body` and not `body.token`? – agoff Feb 20 '23 at 14:38
  • @agoff indeed, when i did the following: `.then(({body}) => { window.localStorage.setItem('accessToken', body.access_token) cy.log(body.access_token) ` I have my log showing the access_token. But when i visit ('/') for my base page (or any page which i can access while logged in), i still am not able to see the user as logged in. – GjoDim Feb 20 '23 at 16:37

0 Answers0