diff --git a/web/src/api/code.ts b/web/src/api/code.ts new file mode 100644 index 0000000..5bb8a50 --- /dev/null +++ b/web/src/api/code.ts @@ -0,0 +1,25 @@ +import { handleApiError } from "."; + +export interface CodeResponse { + code: string; +} + +export const codeApi = async (accessToken: string, nonce: string) => { + const response = await fetch("/api/v1/oauth/code", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${accessToken}`, + }, + body: JSON.stringify({ + nonce, + }), + }); + + if (response.status !== 200 && response.status !== 201) + throw await handleApiError(response); + + const data: CodeResponse = await response.json(); + + return data; +};