MCPcopy Create free account
hub / github.com/pollinations/pollinations / assertStagingAccess

Function assertStagingAccess

shared/auth/api-key.ts:61–83  ·  view source on GitHub ↗
(
    env: {
        ENVIRONMENT?: string;
        STAGING_ALLOWED_GITHUB_IDS?: string;
        STAGING_ALLOWED_EMAILS?: string;
    },
    user:
        | { githubId?: number | null; email?: string | null }
        | null
        | undefined,
)

Source from the content-addressed store, hash-verified

59 * against pre-existing sessions/keys that predate the lockdown. See #11137.
60 */
61export function assertStagingAccess(
62 env: {
63 ENVIRONMENT?: string;
64 STAGING_ALLOWED_GITHUB_IDS?: string;
65 STAGING_ALLOWED_EMAILS?: string;
66 },
67 user:
68 | { githubId?: number | null; email?: string | null }
69 | null
70 | undefined,
71): void {
72 if (env.ENVIRONMENT !== "staging") return;
73 const allowedGithubIds = parseGithubIdList(env.STAGING_ALLOWED_GITHUB_IDS);
74 const allowedEmails = parseEmailList(env.STAGING_ALLOWED_EMAILS);
75 const ghId = user?.githubId;
76 const email = normalizeEmail(user?.email);
77 if (
78 (!ghId || !allowedGithubIds.has(Number(ghId))) &&
79 (!email || !allowedEmails.has(email))
80 ) {
81 throw new StagingAccessDeniedError();
82 }
83}
84
85export function parseEmailList(raw: string | undefined | null): Set<string> {
86 if (!raw) return new Set();

Callers 4

stagingAccessPluginFunction · 0.90
authenticateSessionFunction · 0.90

Calls 3

parseGithubIdListFunction · 0.90
parseEmailListFunction · 0.85
normalizeEmailFunction · 0.85

Tested by

no test coverage detected