Mobile support to come.
import "server-only";
import type { ZodType } from "zod";
import { getSession } from "../supabase";
export const GITDOT_SERVER_URL =
process.env.GITDOT_SERVER_URL || "http://localhost:8080";
export const NotFound = 404 as const;
export type NotFound = typeof NotFound;
export async function authFetch(
url: string,
options?: RequestInit,
): Promise<Response> {
const session = await getSession();
return fetch(url, {
...options,
headers: {
...options?.headers,
...(session && { Authorization: `Bearer ${session.access_token}` }),
},
});
}
export async function authHead(
url: string,
options?: RequestInit,
): Promise<Response> {
return await authFetch(url, {
...options,
method: "HEAD",
});
}
export async function authPost(url: string, request: any): Promise<Response> {
return await authFetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(request),
});
}
export async function authPatch(url: string, request: any): Promise<Response> {
return await authFetch(url, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(request),
});
}
export async function handleResponse<T>(
response: Response,
schema: ZodType<T>,
): Promise<T | null> {
if (!response.ok) {
console.error(
`${response.url} failed:`,
response?.status,
response?.statusText,
);
return null;
}
const data = await response.json();
return schema.parse(data);
}
for the subways
baepaul•96d95bd2d ago
refactoring to head -> /user/{username} for username existence checks
baepaul•2aaa7a43d ago
new 404 error in authorization service and NotFoudn
baepaul•432dc8e9d ago
instrumenting blockers on quite a few places..
baepaul•766630310d ago
inching towards public use
baepaul•ffa992611d ago
renaming env variable
baepaul•65fcc7a11d ago
refactoring dal and dto to separate subdirs and bucket exports
baepaul•1de7f1112d ago