Hi, I want route `/dashboard` to be accessible onl...
# support-questions-legacy
c
Hi, I want route
/dashboard
to be accessible only when the user is logged in. How to do it? I'm making a VueJS + Express app.
s
if you're talking about front-end routes then you would protect them by calling: Session.doesSessionExist()
c
So if I want
/dashboard
to be a frontend route, I need to create Dashboard.vue, dashboardView.html and add DashboardView component to
router\index.ts
, right?
And in order to protect it, I need to add the Session.doesSessionExist()-based function?
s
hmm...i'm not a vuejs guy so I really can't say for sure. this doc is what you would be looking for though:
in the first section they have a snippet of code that looks like this
Copy code
const router = createRouter({ ... })

router.beforeEach((to, from) => {
  // ...
  // explicitly return false to cancel the navigation
  return false
})
a very minimal implementation would be to return the evaluation of Session.doesSessionExist()
if false then cancel the navigation if true then proceed
but ideally you would want to navigate them somewhere else. the next two code blocks go over those examples
c
Oh, yeah, that's what I was looking for! Thanks a lot!
4 Views