This commit is contained in:
Developing-Gamer 2026-06-08 10:57:40 -07:00
parent 4fdd2b3831
commit 47d7124f0d

View File

@ -1,6 +1,7 @@
/// <reference types="vite/client" />
import { StackClientApp, StackProvider, StackTheme } from '@hexclave/react';
import { publishableClientKeyNotNecessarySentinel } from '@hexclave/shared/dist/utils/oauth';
import { runAsynchronously } from '@hexclave/shared/dist/utils/promises';
import {
HeadContent,
Outlet,
@ -49,6 +50,22 @@ function getApiBaseUrlFromEnv(): string | undefined {
return import.meta.env.VITE_HEXCLAVE_API_URL ?? import.meta.env.VITE_STACK_API_URL ?? undefined;
}
function useHexclaveNavigateAdapter() {
const navigate = useNavigate();
return useMemo(() => ({
useNavigate: () => (to: string) => {
runAsynchronously(async () => {
if (to.startsWith("#")) {
await navigate({ hash: to.slice(1) });
} else {
await navigate({ href: to });
}
});
},
}), [navigate]);
}
function FullPageError({ title, message }: { title: string, message: string }) {
return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', minHeight: '100vh' }}>
@ -137,6 +154,7 @@ function RootDocument({ children }: { children: ReactNode }) {
function RootComponent() {
const projectId = useProjectIdFromHostname();
const redirectMethod = useHexclaveNavigateAdapter();
const isValidProjectId = projectId ? (projectId === "internal" || /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(projectId)) : false;
@ -155,9 +173,9 @@ function RootComponent() {
afterSignUp: "/",
afterSignOut: "/handler/sign-in",
},
redirectMethod: { useNavigate: useNavigate as any }
redirectMethod,
});
}, [isValidProjectId, projectId]);
}, [isValidProjectId, projectId, redirectMethod]);
if (projectId === undefined) {
return <FullPageLoadingSkeleton />;