fix: navigation guards for login and register

This commit is contained in:
Sajad Hashemian 2022-02-28 11:33:51 +03:30 committed by Dongsen
parent e2e0b45ee4
commit c08135c652
2 changed files with 19 additions and 0 deletions

View File

@ -46,6 +46,14 @@ describe('Auth', () => {
cy.wrap($el.checkValidity()).should('to.be', false)
})
})
it('should not allow visiting login page when the user is logged in', () => {
cy.login()
cy.visit('/#/login')
cy.url().should('match', /\/#\/$/)
})
})
describe('Register', () => {
@ -81,5 +89,13 @@ describe('Auth', () => {
cy.contains('email has already been taken')
cy.contains('username has already been taken')
})
it('should not allow visiting register page when the user is logged in', () => {
cy.login()
cy.visit('/#/register')
cy.url().should('match', /\/#\/$/)
})
})
})

View File

@ -1,5 +1,6 @@
import { createRouter, createWebHashHistory, RouteParams } from 'vue-router'
import Home from './pages/Home.vue'
import { isAuthorized } from './store/user'
export type AppRouteNames = 'global-feed'
| 'my-feed'
@ -50,11 +51,13 @@ export const router = createRouter({
name: 'login',
path: '/login',
component: () => import('./pages/Login.vue'),
beforeEnter: () => !isAuthorized.value,
},
{
name: 'register',
path: '/register',
component: () => import('./pages/Register.vue'),
beforeEnter: () => !isAuthorized.value,
},
{
name: 'profile',