This repository has been archived on 2025-02-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
iu-quiz-app/middleware/auth.js
2022-11-08 23:04:03 +01:00

12 lines
579 B
JavaScript

export default function ({ $auth, store, route, redirect }) {
const noAuthRoutes = ['login', 'help']
// If Firebase Auth hasn't been initialized yet, redirect to index page
if (!store.state.firebaseInitialized && route.name !== 'index') {
return redirect({ name: 'index' })
}
// If the user attempts to access any site other than those defined in noAuthRoutes without being logged in,
// redirect to login page
else if (store.state.firebaseInitialized && (!$auth.currentUser && !noAuthRoutes.includes(route.name))) {
return redirect({ name: 'login' })
}
}