This code snippet demonstrates the router.beforeEach function in action. It checks if the client is authenticated, and if not, it redirects them to the login page.
router.beforeEach(async (to, from, next) => {
if ( to.name !== 'signup' || to.name !== 'login' ) {
if (await checkAuth()) {
next()
} else {
next({name: 'login'})
}
} else {
next()
}
})