Skip to content

Instantly share code, notes, and snippets.

@jefBinomed
Created November 30, 2018 16:10
Show Gist options
  • Save jefBinomed/7b9b7d389b877e67d473508e75aaf5fb to your computer and use it in GitHub Desktop.
Save jefBinomed/7b9b7d389b877e67d473508e75aaf5fb to your computer and use it in GitHub Desktop.
2018-countdown-router
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