mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 18:33:01 +00:00
add + remove users from organisation
This commit is contained in:
26
packages/frontend/src/lib/server/user/byUsername.ts
Normal file
26
packages/frontend/src/lib/server/user/byUsername.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { UserRecord } from "@issue/shared";
|
||||
import { getAuthHeaders, getServerURL } from "@/lib/utils";
|
||||
import type { ServerQueryInput } from "..";
|
||||
|
||||
export async function byUsername({
|
||||
username,
|
||||
onSuccess,
|
||||
onError,
|
||||
}: {
|
||||
username: string;
|
||||
} & ServerQueryInput) {
|
||||
const url = new URL(`${getServerURL()}/user/by-username`);
|
||||
url.searchParams.set("username", username);
|
||||
|
||||
const res = await fetch(url.toString(), {
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const error = await res.text();
|
||||
onError?.(error || `failed to get user (${res.status})`);
|
||||
} else {
|
||||
const data = (await res.json()) as UserRecord;
|
||||
onSuccess?.(data, res);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user