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

set token and permissions to page

parent 5ba4e18d
Branches JH0009
No related tags found
1 merge request!6set token and permissions to page
......@@ -12,7 +12,7 @@ import ConfirmPlan from '@/views//ConfirmPlan'
Vue.use(Router)
export default new Router({
let router = new Router({
mode: 'history',
routes: [
{
......@@ -33,7 +33,10 @@ export default new Router({
{
path: '/mypage',
name: 'MyPage',
component: MyPage
component: MyPage,
meta: {
requiresAuth: true
}
},
{
path: '/attractionlist',
......@@ -43,12 +46,18 @@ export default new Router({
{
path: '/makeplan',
name: 'MakePlan',
component: MakePlan
component: MakePlan,
meta: {
requiresAuth: true
}
},
{
path: '/shareplan',
name: 'SharePlan',
component: SharePlan
component: SharePlan,
meta: {
requiresAuth: true
}
},
{
path: '/signup',
......@@ -58,7 +67,28 @@ export default new Router({
{
path: '/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 {
user_password: this.user_password
}
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))
}
}
......
......@@ -49,7 +49,7 @@ export default {
methods: {
logout: function () {
this.$store.dispatch('logout')
.then(() => this.$router.push('login'))
.then(() => this.$router.push('/login'))
}
},
computed: {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment