How can I prevent accidental public exposure of Framework7's built-in admin panel when deploying to production?
0 reputation · 08 Jul 2026, 16:40 UTC
0 reputation · 08 Jul 2026, 16:40 UTC
When developing a Framework7‑Vue application I have added an admin section under the route /admin. I want to be certain that this section cannot be reached by unauthenticated users after the app is built and served publicly, but I am unsure how Framework7’s navigation guard mechanism behaves in production builds. The build process bundles the router configuration, and I am concerned that a mis‑configured guard could leave the admin page exposed. What specific steps does Framework7 take to evaluate route guards at runtime, and how can I verify that the guard is enforced after the app is deployed? Are there any built‑in utilities or test modes that simulate an unauthenticated request to confirm the protection works?
26525 reputation · 09 Jul 2026, 01:06 UTC
Framework7’s navigation guards run inside the browser. When you build the app, the router configuration—including any beforeEnter hooks—is bundled into a static JavaScript file. The guard can prevent a transition, but it does not remove the code for the protected page from the bundle. A user who knows the route can still request the chunk, so client‑side guards alone are insufficient for production security.
const routes = [
{ path: '/', component: Home },
...(process.env.NODE_ENV === 'development' ? [
{ path: '/admin', component: Admin, beforeEnter: authGuard }
] : [])
];
During a production build process.env.NODE_ENV is production, so the array is empty and the Admin component is never bundled./admin path. For Nginx:
location /admin {
deny all;
# or use basic auth
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
This stops the request before the JavaScript bundle is served.index.html and the main JS chunk. Search for a unique string from the Admin component (e.g., a component name or template text). If it is absent, the exclusion worked./admin. You should receive a 404 Not Found (route excluded) or a 403 Forbidden (server block). If you see the page, the guard or exclusion failed.Framework7 does not ship a built‑in test mode for unauthenticated requests, so manual verification or a simple CI script that fetches /admin and asserts a non‑200 status is the most reliable approach.
Use comments to ask for clarification. Post a solution as an answer.
2,340 reputation · 09 Jul 2026, 00:52 UTC
Framework7’s router is built on Vue Router, so its beforeEnter (or global beforeEach) guards run only after the route’s component chunk has been resolved. If the admin route is defined with a lazy‑loaded component (() => import('./Admin.vue')), the guard can prevent the chunk from being fetched when the user is unauthenticated, because the navigation is cancelled before the dynamic import resolves. To verify this in production:
https://your‑site.com/admin.Thus, combining lazy loading with a guard that checks authentication before the route resolves gives you a verifiable, production‑safe way to keep the admin panel hidden.