-
Notifications
You must be signed in to change notification settings - Fork 0
/
load-context.ts
46 lines (41 loc) · 918 Bytes
/
load-context.ts
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { AppLoadContext } from "react-router";
import type { PlatformProxy } from "wrangler";
import { z } from "zod";
const schema = z.object({
CLERK_SECRET_KEY: z.string(),
CLERK_PUBLISHABLE_KEY: z.string(),
CLERK_SIGN_UP_URL: z.string(),
CLERK_SIGN_IN_URL: z.string(),
});
declare module "react-router" {
interface AppLoadContext {
env: z.infer<typeof schema> & {
cf: CfProperties;
};
}
}
interface CloudflareLoadContext {
context: {
cloudflare: Omit<PlatformProxy<unknown>, "dispose">;
};
request: Request;
}
export function getLoadContext({
context,
}: CloudflareLoadContext): AppLoadContext {
const {
CLERK_SECRET_KEY,
CLERK_PUBLISHABLE_KEY,
CLERK_SIGN_UP_URL,
CLERK_SIGN_IN_URL,
} = schema.parse(context.cloudflare.env);
return {
env: {
cf: context.cloudflare.cf,
CLERK_SECRET_KEY,
CLERK_PUBLISHABLE_KEY,
CLERK_SIGN_UP_URL,
CLERK_SIGN_IN_URL,
},
};
}