From 0b08a78f87122a52eca166514f1cdaabfb23b684 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 20 May 2021 12:39:33 +0100 Subject: [PATCH] Fixing an issue with checkAuth function not checking response status before attempting to get JSON. --- packages/builder/src/stores/portal/auth.js | 8 ++++---- packages/server/src/api/controllers/dev.js | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/stores/portal/auth.js b/packages/builder/src/stores/portal/auth.js index baf5f1bfb4..c642a5708d 100644 --- a/packages/builder/src/stores/portal/auth.js +++ b/packages/builder/src/stores/portal/auth.js @@ -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 => { diff --git a/packages/server/src/api/controllers/dev.js b/packages/server/src/api/controllers/dev.js index 86b9a11c23..2e90fb83e7 100644 --- a/packages/server/src/api/controllers/dev.js +++ b/packages/server/src/api/controllers/dev.js @@ -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)