Skip to content
Snippets Groups Projects
Commit 1859e656 authored by jaypae95's avatar jaypae95
Browse files

set token and permissions to page

parent 5ba4e18d
No related branches found
No related tags found
1 merge request!6set token and permissions to page
...@@ -12,7 +12,7 @@ import ConfirmPlan from '@/views//ConfirmPlan' ...@@ -12,7 +12,7 @@ import ConfirmPlan from '@/views//ConfirmPlan'
Vue.use(Router) Vue.use(Router)
export default new Router({ let router = new Router({
mode: 'history', mode: 'history',
routes: [ routes: [
{ {
...@@ -33,7 +33,10 @@ export default new Router({ ...@@ -33,7 +33,10 @@ export default new Router({
{ {
path: '/mypage', path: '/mypage',
name: 'MyPage', name: 'MyPage',
component: MyPage component: MyPage,
meta: {
requiresAuth: true
}
}, },
{ {
path: '/attractionlist', path: '/attractionlist',
...@@ -43,12 +46,18 @@ export default new Router({ ...@@ -43,12 +46,18 @@ export default new Router({
{ {
path: '/makeplan', path: '/makeplan',
name: 'MakePlan', name: 'MakePlan',
component: MakePlan component: MakePlan,
meta: {
requiresAuth: true
}
}, },
{ {
path: '/shareplan', path: '/shareplan',
name: 'SharePlan', name: 'SharePlan',
component: SharePlan component: SharePlan,
meta: {
requiresAuth: true
}
}, },
{ {
path: '/signup', path: '/signup',
...@@ -58,7 +67,28 @@ export default new Router({ ...@@ -58,7 +67,28 @@ export default new Router({
{ {
path: '/confirmplan', path: '/confirmplan',
name: 'ConfirmPlan', name: 'ConfirmPlan',
component: ConfirmPlan component: ConfirmPlan,
meta: {
requiresAuth: true
}
} }
] ]
}) })
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
console.log(localStorage.getItem('token'))
if (localStorage.getItem('token') == null) {
next({
path: '/login',
params: {nextUrl: to.fullPath}
})
} else {
next()
}
} else {
next()
}
})
export default router
...@@ -27,7 +27,11 @@ export default { ...@@ -27,7 +27,11 @@ export default {
user_password: this.user_password user_password: this.user_password
} }
this.$store.dispatch('login', data) this.$store.dispatch('login', data)
.then(() => this.$router.push('/')) .then(res => {
localStorage.setItem('user', JSON.stringify(res.data.user))
localStorage.setItem('token', res.data.token)
this.$router.push('/')
})
.catch(err => console.log(err)) .catch(err => console.log(err))
} }
} }
......
...@@ -49,7 +49,7 @@ export default { ...@@ -49,7 +49,7 @@ export default {
methods: { methods: {
logout: function () { logout: function () {
this.$store.dispatch('logout') this.$store.dispatch('logout')
.then(() => this.$router.push('login')) .then(() => this.$router.push('/login'))
} }
}, },
computed: { computed: {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment