From 6d66d12a9e4d548b0c7580a0fe58b023813e3202 Mon Sep 17 00:00:00 2001 From: Akash K <57758277+amk-dev@users.noreply.github.com> Date: Thu, 7 Mar 2024 23:43:20 +0530 Subject: [PATCH] feat: common changes for site protection (#3878) --- packages/hoppscotch-common/locales/en.json | 5 +++++ packages/hoppscotch-common/src/modules/index.ts | 2 +- packages/hoppscotch-common/src/modules/router.ts | 12 +++++++++--- packages/hoppscotch-common/src/pages/enter.vue | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/hoppscotch-common/locales/en.json b/packages/hoppscotch-common/locales/en.json index 1b07f6eb9..b69ed1a91 100644 --- a/packages/hoppscotch-common/locales/en.json +++ b/packages/hoppscotch-common/locales/en.json @@ -994,5 +994,10 @@ "personal": "My Workspace", "team": "Team Workspace", "title": "Workspaces" + }, + "site_protection": { + "login_to_continue": "Login to continue", + "login_to_continue_description": "You need to be logged in to access this Hoppscotch Enterprise Instance.", + "error_fetching_site_protection_status": "Something Went Wrong While Fetching Site Protection Status" } } diff --git a/packages/hoppscotch-common/src/modules/index.ts b/packages/hoppscotch-common/src/modules/index.ts index f4ec9d65c..b4c63f694 100644 --- a/packages/hoppscotch-common/src/modules/index.ts +++ b/packages/hoppscotch-common/src/modules/index.ts @@ -34,7 +34,7 @@ export type HoppModule = { to: RouteLocationNormalized, from: RouteLocationNormalized, router: Router - ) => void + ) => void | Promise /** * Called by the router to tell all the modules that a route navigation has completed diff --git a/packages/hoppscotch-common/src/modules/router.ts b/packages/hoppscotch-common/src/modules/router.ts index 79ea37d48..0e18dd839 100644 --- a/packages/hoppscotch-common/src/modules/router.ts +++ b/packages/hoppscotch-common/src/modules/router.ts @@ -47,15 +47,21 @@ export default { routes, }) - router.beforeEach((to, from) => { + router.beforeEach(async (to, from) => { _isLoadingInitialRoute.value = isInitialRoute(from) + const onBeforeRouteChangePromises: Promise[] = [] + HOPP_MODULES.forEach((mod) => { - mod.onBeforeRouteChange?.(to, from, router) + const res = mod.onBeforeRouteChange?.(to, from, router) + if (res) onBeforeRouteChangePromises.push(res) }) platform.addedHoppModules?.forEach((mod) => { - mod.onBeforeRouteChange?.(to, from, router) + const res = mod.onBeforeRouteChange?.(to, from, router) + if (res) onBeforeRouteChangePromises.push(res) }) + + await Promise.all(onBeforeRouteChangePromises) }) // Instead of this a better architecture is for the router diff --git a/packages/hoppscotch-common/src/pages/enter.vue b/packages/hoppscotch-common/src/pages/enter.vue index 9c7adc5c1..9dce59a86 100644 --- a/packages/hoppscotch-common/src/pages/enter.vue +++ b/packages/hoppscotch-common/src/pages/enter.vue @@ -44,4 +44,5 @@ export default defineComponent({ meta: layout: empty + onlyGuest: true