mirror of
https://github.com/KevinMidboe/seasoned.git
synced 2026-04-26 17:43:37 +00:00
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 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);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user