Logout route that clears localstorage for anything set clientside.

This commit is contained in:
2020-04-09 20:53:19 +02:00
committed by KevinMidboe
parent 65bbc453e6
commit 73afb34964
2 changed files with 20 additions and 6 deletions

View File

@@ -286,7 +286,7 @@ const register = (username, password) => {
})
}
const login = (username, password) => {
const login = (username, password, throwError=false) => {
const url = new URL('v1/user/login', SEASONED_URL)
const options = {
method: 'POST',
@@ -295,11 +295,14 @@ const login = (username, password) => {
}
return fetch(url.href, options)
.then(resp => resp.json())
.catch(error => {
console.error('Unexpected error occured before receiving response. Error:', error)
// TODO log to sentry the issue here
throw error
.then(resp => {
if (resp.status == 200)
return resp.json();
if (throwError)
throw resp;
else
console.error("Error occured when trying to sign in.\nError:", resp);
})
}

View File

@@ -65,6 +65,17 @@ let routes = [
path: '/404',
component: (resolve) => require(['./components/404.vue'], resolve)
},
{
name: 'logout',
path: '/logout',
component: {
template: '<div></div>',
created() {
localStorage.clear();
this.$router.push({ name: 'home' });
}
}
},
{
path: '*',
redirect: '/'