From 34c1ce7652310ed70aa9a6e21826df2535e4ece8 Mon Sep 17 00:00:00 2001 From: LandaMm Date: Sun, 25 May 2025 14:12:27 +0200 Subject: [PATCH] feat: generate code API --- web/src/api/code.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 web/src/api/code.ts 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; +};