Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/lib/shared/api/mutator/custom-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ const tryGetRequestEvent = () => {
export const customFetch = async <T>(url: string, options: RequestInit): Promise<T> => {
const event = tryGetRequestEvent();

// Deployed Workers get a Secrets Store binding; local dev and prerender get a plain string
const token = event?.platform?.env.SERVER_API_TOKEN ?? envPrivate.SERVER_API_TOKEN;
const serverApiToken = typeof token === "string" ? token : await token.get();
// Deployed Workers get a Secrets Store binding (also surfaced through $env/dynamic/private);
// local dev and prerender get a plain string. Prefer the dynamic env: during `vite build` the
// platform proxy exposes a binding whose get() fails because the secret only exists remotely.
const token =
(envPrivate.SERVER_API_TOKEN as App.Platform["env"]["SERVER_API_TOKEN"]) ?? event?.platform?.env.SERVER_API_TOKEN;
const serverApiToken = typeof token === "string" ? token : ((await token?.get()) ?? "");

const requestInit: RequestInit = {
...options,
Expand Down
Loading