Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot reach Routes with AuthGuard #4

Open
ebds opened this issue Jul 19, 2018 · 0 comments
Open

Cannot reach Routes with AuthGuard #4

ebds opened this issue Jul 19, 2018 · 0 comments

Comments

@ebds
Copy link

ebds commented Jul 19, 2018

First I want to thank you for this good starting point!

I have a problem with the routing system here, as I cannot reach /profile or /dashboard (whatever restricted route given), as it redirects me always to the "/" home page.

I do not want to have a seperate /signup and /signIn page, so I store them in a dialog and the login and signup itself works fine and as expected.

Somehow, within the auth-guard.js I set in the else condition next('/') instead next('/signup') (as I dont want to have this extra route)

Is this maybe causing the problem? I did not make any other changes to your code, besides this one.

If you need further information, please contact me.

Here is my router index.js and auth-guard.js

import Vue from 'vue'
import Router from 'vue-router'
import AuthGuard from './auth-guard'


const Home = () => import('@/components/Home')
const Profile = () => import('@/components/User/Profile')
const Dashboard = () => import('@/components/Dashboard/Layout')

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home
    },
    {
      path: '/dashboard',
      name: 'Dashboard',
      component: Dashboard,
      beforeEnter: AuthGuard
    },
    {
      path: '/profile',
      name: 'Profile',
      component: Profile,
      beforeEnter: AuthGuard,
      children: [
        {
          path: '/settings',
          name: 'Settings',
          component: () => import('@/components/User/Settings')
        }
      ]
    }
  ],
  mode: 'history'
})

and the auth-guard.js

import {store} from '../store'

export default (to, from, next) => {
  if (store.getters.user) {
    next()
  } else {
    next('/')
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant