9deb320cf6
Rename the global Sidebar route, UI, assets, analytics, and payment return context to Profile. Add accessible message-avatar navigation and preserve the source character across auth and logout flows. BREAKING CHANGE: /sidebar has been removed; use /profile instead.
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { ROUTES } from "./routes";
|
|
|
|
export type RouteAccess =
|
|
| "public"
|
|
| "guestEntry"
|
|
| "session"
|
|
| "realUser"
|
|
| "authOnly";
|
|
|
|
const GLOBAL_ROUTE_ACCESS: Partial<Record<string, RouteAccess>> = {
|
|
[ROUTES.root]: "public",
|
|
[ROUTES.splash]: "authOnly",
|
|
[ROUTES.auth]: "authOnly",
|
|
[ROUTES.chat]: "guestEntry",
|
|
[ROUTES.privateRoom]: "guestEntry",
|
|
[ROUTES.tip]: "public",
|
|
[ROUTES.externalEntry]: "public",
|
|
[ROUTES.profile]: "realUser",
|
|
[ROUTES.feedback]: "session",
|
|
[ROUTES.subscription]: "realUser",
|
|
[ROUTES.coinsRules]: "public",
|
|
};
|
|
|
|
const CHARACTER_ROUTE_ACCESS: Readonly<Record<string, RouteAccess>> = {
|
|
splash: "authOnly",
|
|
chat: "guestEntry",
|
|
"private-room": "guestEntry",
|
|
tip: "public",
|
|
};
|
|
|
|
export function getRouteAccess(pathname: string): RouteAccess {
|
|
const globalAccess = GLOBAL_ROUTE_ACCESS[pathname];
|
|
if (globalAccess) return globalAccess;
|
|
|
|
const match = pathname.match(/^\/characters\/[^/]+\/([^/]+)\/?$/);
|
|
return (match?.[1] && CHARACTER_ROUTE_ACCESS[match[1]]) || "public";
|
|
}
|
|
|
|
export function isInternalRoute(value: string | null | undefined): boolean {
|
|
return Boolean(value && value.startsWith("/") && !value.startsWith("//"));
|
|
}
|