Unauthenticated Users

Before continuing, make sure you have read the Authentication Overview & Setup lesson first.

it("should redirect unauthenticated user to signin page", () => {
  cy.visit("/personal")
  cy.location("pathname").should("equal", "/signin")
})

First, we attempt to cy.visit() the URL /personal, a protected route that only logged-in users can access.

cy.visit("/personal")

Finally, we assert that the application redirects users who are not logged in back to the /signin page.

cy.location("pathname").should("equal", "/signin")

Screenshot of browser with Cypress command log showing passing test, shown as green, with the Real World App login page shown as the application under test.

This is a straightforward test, but it is testing some critical functionality, as we do not want unauthorized users to gain access to our application. Now we can be confident that any unauthorized users will be automatically redirected to the Sign-in page.