ghostguild-org/app/middleware/coming-soon.global.js
Jennie Robinson Faber 0927b66b4f
All checks were successful
Test / vitest (push) Successful in 11m15s
Test / playwright (push) Successful in 16m10s
Test / Notify on failure (push) Has been skipped
fix(coming-soon): let logged-in admins bypass the gate
Admins can now load the public site and their dashboard while coming-soon
mode is on, instead of being redirected to /coming-soon for everything
outside /admin/*.
2026-05-01 14:13:43 +01:00

35 lines
1.1 KiB
JavaScript

export default defineNuxtRouteMiddleware(async (to, from) => {
const config = useRuntimeConfig();
const isComingSoonMode =
config.public.comingSoon === "true" || config.public.comingSoon === true;
// Only enforce coming soon mode if enabled
if (!isComingSoonMode) {
return;
}
// Allow access to the coming-soon page, OIDC login, and admin routes
if (
to.path === "/coming-soon" ||
to.path === "/auth/wiki-login" ||
to.path === "/auth/oidc-error" ||
to.path === "/auth/logout-confirm" ||
to.path === "/auth/logout-success" ||
to.path === "/verify" ||
to.path.startsWith("/admin")
) {
return;
}
// Logged-in admins bypass coming-soon (and see the public site + their dashboard)
try {
const headers = import.meta.server ? useRequestHeaders(["cookie"]) : undefined;
const member = await $fetch("/api/auth/member", { headers });
if (member?.role === "admin") return;
} catch {
// Not authenticated — fall through to redirect
}
// Redirect all other routes to coming-soon
return navigateTo("/coming-soon");
});