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) { if (response.data.success) {
Cookies.set('session', response.data.message, { expires: 30 }) Cookies.set('session', response.data.message, { expires: 30 })
console.log('cookie', Cookies.get()) console.log('cookie', Cookies.get())
this.$router.push('about')
} }
}) })
} }

View file

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

View file

@ -15,19 +15,38 @@
</template> </template>
<script> <script>
import * as Cookies from 'js-cookie'
import axios from '@/plugins/axios'
import LoginForm from '@/components/forms/Login.vue' import LoginForm from '@/components/forms/Login.vue'
import RegisterForm from '@/components/forms/Register.vue' import RegisterForm from '@/components/forms/Register.vue'
export default { export default {
name: 'Home', name: 'Home',
data() { data() {
return { return {
dialog: false dialog: false
} }
}, },
components: { components: {
LoginForm, LoginForm,
RegisterForm 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> </script>