From 74ab884b7a03bd63a0f50a5c62e6ab7009862474 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 10 May 2023 02:24:50 +0200 Subject: [PATCH] Proper redirects upon `/execute` failure. If a call to `/execute` fails with a 401 or 412 status, then redirect the user to `/register` or `/login`. --- .../backend/http/webapp/src/utils/Api.vue | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/platypush/backend/http/webapp/src/utils/Api.vue b/platypush/backend/http/webapp/src/utils/Api.vue index 5118813d9..12305fcee 100644 --- a/platypush/backend/http/webapp/src/utils/Api.vue +++ b/platypush/backend/http/webapp/src/utils/Api.vue @@ -36,6 +36,25 @@ export default { } }) .catch((error) => { + // No users present -> redirect to the registration page + if ( + error?.response?.data?.code === 412 && + window.location.href.indexOf('/register') < 0 + ) { + window.location.href = '/register?redirect=' + window.location.href + return + } + + // Unauthorized -> redirect to the login page + if ( + error?.response?.data?.code === 401 && + window.location.href.indexOf('/login') < 0 + ) { + window.location.href = '/login?redirect=' + window.location.href + return + } + + console.log(error) if (showError) this.notify({ text: error,