From 729015d71971ea0b793842125dcea503c62f28d0 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Wed, 21 Feb 2024 00:11:31 -0500 Subject: [PATCH] [+] SDK confirmEmail --- AquaNet/src/libs/sdk.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/AquaNet/src/libs/sdk.ts b/AquaNet/src/libs/sdk.ts index 28a0eaf9..d88d09e0 100644 --- a/AquaNet/src/libs/sdk.ts +++ b/AquaNet/src/libs/sdk.ts @@ -33,7 +33,7 @@ export function fetchWithParams(input: URL | RequestInfo, init?: RequestInitWith export async function post(endpoint: string, params: any, init?: RequestInitWithParams): Promise { // Add token if exists const token = localStorage.getItem('token') - if (token) params = { ...(params ?? {}), token } + if (token && !('token' in params)) params = { ...(params ?? {}), token } let res = await fetchWithParams(AQUA_HOST + endpoint, { method: 'POST', @@ -61,12 +61,22 @@ export async function post(endpoint: string, params: any, init?: RequestInitWith * * @param user */ -export async function register(user: { username: string, email: string, password: string, turnstile: string }) { +async function register(user: { username: string, email: string, password: string, turnstile: string }) { return await post('/api/v2/user/register', user) } -export async function login(user: { email: string, password: string, turnstile: string }) { +async function login(user: { email: string, password: string, turnstile: string }) { const data = await post('/api/v2/user/login', user) // Put token into local storage localStorage.setItem('token', data.token) +} + +async function confirmEmail(token: string) { + return await post('/api/v2/user/confirm-email', { token }) +} + +export const USER = { + register, + login, + confirmEmail } \ No newline at end of file