login/logout routing

This commit is contained in:
Jörn-Michael Miehe 2019-05-07 22:28:51 +02:00
parent 84ec601e2a
commit ed18dce3ea
3 changed files with 31 additions and 3 deletions

View file

@ -56,6 +56,7 @@ export default {
if (response.data.success) {
Cookies.set('session', response.data.message, { expires: 30 })
console.log('cookie', Cookies.get())
this.$router.push('about')
}
})
}

View file

@ -23,6 +23,11 @@ export default {
}),
methods: {
goHome() {
Cookies.remove('session')
this.$router.push({ name: 'home' })
},
logout() {
axios
.post('/user/logout', {
@ -30,8 +35,7 @@ export default {
})
.then(response => {
if (response.data.success) {
Cookies.remove('session')
this.$router.push({name: 'home'})
this.goHome()
}
})
}
@ -43,7 +47,11 @@ export default {
session: Cookies.get('session')
})
.then(response => {
if (response.data.success) {
this.sessionID = response.data.message
} else {
this.goHome()
}
})
}
}

View file

@ -15,19 +15,38 @@
</template>
<script>
import * as Cookies from 'js-cookie'
import axios from '@/plugins/axios'
import LoginForm from '@/components/forms/Login.vue'
import RegisterForm from '@/components/forms/Register.vue'
export default {
name: 'Home',
data() {
return {
dialog: false
}
},
components: {
LoginForm,
RegisterForm
},
mounted() {
if (Cookies.get('session')) {
axios
.post('/user/login', {
session: Cookies.get('session')
})
.then(response => {
if (response.data.success) {
this.$router.push({ name: 'about' })
}
})
}
}
}
</script>