Created
November 30, 2018 16:10
-
-
Save jefBinomed/7b9b7d389b877e67d473508e75aaf5fb to your computer and use it in GitHub Desktop.
2018-countdown-router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const secureRoute = (to, from, next) => { | |
const currentRoute = to.path; | |
if (from.path === '/wait') { | |
next(); | |
}else { | |
next('/wait'); | |
firebase.auth().onAuthStateChanged((user) => { | |
if(user) { | |
next(currentRoute); | |
} else { | |
next('/auth'); | |
} | |
}); | |
} | |
} | |
const routes = [ | |
{ | |
// The main page for users | |
path: '/', | |
component: Game, | |
beforeEnter: secureRoute | |
}, | |
{ | |
// The page to display when the countdown is over | |
path: '/final', | |
component: Final | |
}, | |
{ | |
// The page to show when the user is waiting for his connection | |
path: '/wait', | |
component: Wait | |
}, | |
{ | |
// The page of authentication | |
path: '/auth', | |
component: Auth | |
}, | |
{ | |
// The main screen with the countdown | |
path: '/countdown', | |
component: Countdown, | |
beforeEnter: secureRoute | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment