← Back to library
Cypressauthintermediatev10+
Assert unauthenticated redirect
Clear session data and confirm that protected routes redirect to /login.
1it('redirects to /login when not authenticated', () => {
2 // Wipe any existing auth state
3 cy.clearLocalStorage();
4 cy.clearCookies();
5
6 cy.visit('/dashboard', { failOnStatusCode: false });
7
8 cy.url().should('include', '/login');
9 cy.get('h1').should('contain.text', 'Sign in');
10});#redirect#protected#unauthenticated#clearLocalStorage