title: Cypress login using request method
body: <p>I register &amp; login a user, however, when in my test I navigate to a page behind authentication, Cypress fails &amp; takes me back to the login page. From the looks of it, the <code>before</code> function is successfully executed (as verified by the API log). Here is my code:</p>
  
  <pre><code>describe("Dashboard page", () =&gt; {
    before(() =&gt; {
      cy.fixture("authUserRegistrationDetail.json").then(userDetail =&gt; {
        cy.fixture("authUserLoginDetail.json").then(userLoginDetail =&gt; {
          cy.visit("http://localhost:3000/login");
          cy.get(".cookieConsent button").click();
          // create a random email for registration
          userDetail.email = `${Math.random()
            .toString(36)
            .slice(-5)}@aaa.aaa`;
          // share the email between userLogin &amp; userRegistration obj
          userLoginDetail.email = userDetail.email;
          // register the user
          cy.request("POST", "http://localhost:9000/users/", userDetail)
            .its("body")
          // login the same user
          cy.request("POST", "http://localhost:9000/api-token-auth/", userLoginDetail).then($res =&gt; {
            cy.request({
              url: "http://localhost:9000/loggedinuser/",
              headers: {
                Authorization: `Token ${$res.body.token}`
              }
            });
          });
        });
      });
    });
  
    // run the test
    it("visits the dashboard...", () =&gt; {
      cy.visit("http://localhost:3000/dashboard/");
      cy.get("h2").contains("Your deals");
    });
  });
  </code></pre>
  
  <p>Once the code is run, the test fails on assertion and the user is not logged in. Here is the screenshot of the test result.  I get a status code 200 when user signs up &amp; then logs in. Why is the user login not persisting in the tests &amp; the dashboard link fails.</p>
  
  <p><strong>EDIT:
  I just realised that I am programmatically logging in, however, once logged in, how do I get Cypress browser to recognise the change in state &amp; that the user is logged in. I.e, how do I refresh the Cypress screen to recognise the the user login?</strong></p>
  
  <p><a href="https://i.stack.imgur.com/jLUBD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jLUBD.png" alt="cypress screen"></a></p>