File size: 882 Bytes
05e7451
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f6add23
 
05e7451
f6add23
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { publicEnv } from "./publicEnv";

function readAdminPathSecret(): string {
  // Client: runtime-config.js (HF/Docker) or NEXT_PUBLIC_* from next dev.
  if (typeof window !== "undefined") {
    return publicEnv("NEXT_PUBLIC_ADMIN_PATH_SECRET");
  }
  // Server: prefer non-NEXT_PUBLIC so HF/Docker runtime env is not build-inlined.
  const env = process.env as Record<string, string | undefined>;
  return (
    env.ADMIN_PATH_SECRET?.trim() ||
    env.NEXT_PUBLIC_ADMIN_PATH_SECRET?.trim() ||
    ""
  );
}

/** Login/admin UI path segment from env (literal URL, not encoded). */
export function adminPathSlug(): string {
  const secret = readAdminPathSecret();
  if (!secret) return "";
  return secret.replace(/^\/+|\/+$/g, "");
}

export function isAdminSlug(slug: string): boolean {
  const expected = adminPathSlug();
  return Boolean(expected) && slug === expected;
}