Skip to content

How to access store in beforeEnter #26

@Ridermansb

Description

@Ridermansb

How access store in beforeEnter ?

// main.js
import store from './store'
import router from './router'
import { sync } from 'vuex-router-sync'

sync(store, router)
// routes.js
function requireAuth (to, from, next) {
  if (!store.getters.isAuthenticated) { /// THIS NOT WORK, HOW TO ACCESS STORE?
    window.location.href = '/auth/v1/auth0/connect'
  } else {
    next()
  }
}

export default [
  {
    path: '/', component: Timeline
  },

  {
    path: '/events',
    component: Events,
    beforeEnter: requireAuth
  }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions