Fixing an issue with checkAuth function not checking response status before attempting to get JSON.

This commit is contained in:
mike12345567 2021-05-20 12:39:33 +01:00
parent 3e92311101
commit 0b08a78f87
2 changed files with 7 additions and 5 deletions

View File

@ -8,11 +8,11 @@ export function createAuthStore() {
subscribe: store.subscribe,
checkAuth: async () => {
const response = await api.get("/api/admin/users/self")
const user = await response.json()
if (response.status === 200) {
store.update(state => ({ ...state, user }))
} else {
if (response.status !== 200) {
store.update(state => ({ ...state, user: null }))
} else {
const user = await response.json()
store.update(state => ({ ...state, user }))
}
},
login: async creds => {

View File

@ -16,7 +16,9 @@ async function redirect(ctx, method) {
body: ctx.request.body,
})
)
ctx.body = await response.json()
if (response.status !== 200) {
ctx.throw(response.status, response.statusText)
}
const cookie = response.headers.get("set-cookie")
if (cookie) {
ctx.set("set-cookie", cookie)