DEV Community

Discussion on: Vue + Firebase authentication

Collapse
 
maximejnq profile image
Maxime Junique • Edited

Hey Brian, great article but two things could be improved.

You should be sending an email verification during register.

data.user.sendEmailVerification();

You should use onAuthStateChanged you retrieve the current user in your BeforeEach like that:

router.beforeEach((to, from, next) => {
firebase.auth().onAuthStateChanged(function(user) {
let requiresAuth = to.matched.some(record => record.meta.requiresAuth);
if (requiresAuth && !user) next("login");
else next();
});
});

Best,

Maxime