From 0a882f595a9893f61a1c3151b66f977e745e083c Mon Sep 17 00:00:00 2001 From: rustybrooks Date: Sat, 12 Oct 2024 12:58:30 -0500 Subject: [PATCH] cleanup --- src/ui/src/api/api-fetch.ts | 4 ++-- src/ui/src/components/Login.tsx | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/ui/src/api/api-fetch.ts b/src/ui/src/api/api-fetch.ts index f2224da..83eb62d 100644 --- a/src/ui/src/api/api-fetch.ts +++ b/src/ui/src/api/api-fetch.ts @@ -41,13 +41,13 @@ export const apiFetch = async (url: string, options: Record) headers, }); if (!res.ok) { - if (res.status === 401) { + if (res.status === 401 || res.status === 403) { throw new UnauthenticatedError('Unauthenticated'); } throw new Error('An error occurred while fetching the data.'); } - return { data: (await res.json()) as T, response: res }; + return (await res.json()) as T; }; export const useUrl = ( diff --git a/src/ui/src/components/Login.tsx b/src/ui/src/components/Login.tsx index cb4fb1b..19ff191 100644 --- a/src/ui/src/components/Login.tsx +++ b/src/ui/src/components/Login.tsx @@ -6,13 +6,10 @@ import { User } from '../api/DTOs'; const login = async (navigate: NavigateFunction, username: string, password: string): Promise => { try { - const { response, data } = await apiFetch(apiUrl('USERS_LOGIN')(), { + await apiFetch(apiUrl('USERS_LOGIN')(), { method: 'POST', body: JSON.stringify({ username, password }), }); - if (response.status === 403) { - return (data as any).details.detail; - } navigate('/'); } catch (error) { console.log(error); @@ -24,13 +21,10 @@ const login = async (navigate: NavigateFunction, username: string, password: str const signup = async (navigate: NavigateFunction, username: string, password: string, password2: string): Promise => { try { - const { response, data } = await apiFetch(apiUrl('USERS_SIGNUP')(), { + await apiFetch(apiUrl('USERS_SIGNUP')(), { method: 'POST', body: JSON.stringify({ username, password, password2 }), }); - if (response.status === 403) { - return (data as any).details.detail; - } navigate('/'); } catch (error) { console.log(error);