Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

feat: common changes for site protection (#3878)

Akash K6d66d12a9e4d
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<void>
/**
* 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 <HoppModule>{
routes,
})
- router.beforeEach((to, from) => {
+ router.beforeEach(async (to, from) => {
_isLoadingInitialRoute.value = isInitialRoute(from)
+ const onBeforeRouteChangePromises: Promise<any>[] = []
+
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({
<route lang="yaml">
meta:
layout: empty
+ onlyGuest: true
</route>