cohki0305 / conf

0 stars 0 forks source link

ログインしていないと Room が作成・参照できないようにする #10

Open cohki0305 opened 6 years ago

cohki0305 commented 6 years ago

概要

cohki0305 commented 6 years ago

router.js にて以下のようなものを記述するといい感じにリダイレクト設定ができる。


router.beforeEach((to, from, next) => {
  const requiresAuth = to.matched.some(record => record.meta.requiresAuth)
  const currentUser = firebase.auth().currentUser
  if (requiresAuth) {
    if (!currentUser) {
      next({
        path: '/signin',
        query: {
          redirect: to.fullPath
        }
      })
    } else {
      next()
    }
  } else {
    next()
  }
})