Vue Router Authentication

Dec 15, 2019

Refer Setup Firebase Email Authentication (Web) with Whitelisted emails using Vue.js and Vue Router.

Edit main.js.

const app = {  name: 'My App',  version: '1.0.1',  isAuthenticated: false}Vue.prototype.$app = app// TODO: check is authenticated// app.isAuthenticated = true

Edit router/index.js.

router.beforeEach((to, from, next) => {  if (to.fullPath === '/about') {    next()    return  }  const isAuthenticated = Vue.prototype.$app.isAuthenticated  if (!isAuthenticated && to.fullPath !== '/signin') next('/signin')  else next()})

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.