fix: navigation guards for login and register
This commit is contained in:
parent
e2e0b45ee4
commit
c08135c652
|
|
@ -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', /\/#\/$/)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Reference in New Issue