Logout route that clears localstorage for anything set clientside.
This commit is contained in:
15
src/api.js
15
src/api.js
@@ -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 url = new URL('v1/user/login', SEASONED_URL)
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -295,11 +295,14 @@ const login = (username, password) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return fetch(url.href, options)
|
return fetch(url.href, options)
|
||||||
.then(resp => resp.json())
|
.then(resp => {
|
||||||
.catch(error => {
|
if (resp.status == 200)
|
||||||
console.error('Unexpected error occured before receiving response. Error:', error)
|
return resp.json();
|
||||||
// TODO log to sentry the issue here
|
|
||||||
throw error
|
if (throwError)
|
||||||
|
throw resp;
|
||||||
|
else
|
||||||
|
console.error("Error occured when trying to sign in.\nError:", resp);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,17 @@ let routes = [
|
|||||||
path: '/404',
|
path: '/404',
|
||||||
component: (resolve) => require(['./components/404.vue'], resolve)
|
component: (resolve) => require(['./components/404.vue'], resolve)
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'logout',
|
||||||
|
path: '/logout',
|
||||||
|
component: {
|
||||||
|
template: '<div></div>',
|
||||||
|
created() {
|
||||||
|
localStorage.clear();
|
||||||
|
this.$router.push({ name: 'home' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '*',
|
path: '*',
|
||||||
redirect: '/'
|
redirect: '/'
|
||||||
|
|||||||
Reference in New Issue
Block a user