fix architecture and write new tests

This commit is contained in:
root
2026-06-10 00:40:19 -04:00
parent 560da1cadf
commit 80a597bc10
377 changed files with 84020 additions and 1337 deletions
+2 -10
View File
@@ -46,26 +46,18 @@ export class RenterAuthError extends Error {
}
}
function getRenterToken() {
return window.localStorage.getItem('renter_token')
}
async function renterFetch<T>(path: string, init?: RequestInit): Promise<T> {
const token = getRenterToken()
if (!token) throw new RenterAuthError()
const res = await fetch(`${API_BASE}${path}`, {
...init,
credentials: 'include',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
...(init?.headers ?? {}),
},
})
const json = await res.json().catch(() => null)
if (res.status === 401) {
window.localStorage.removeItem('renter_token')
throw new RenterAuthError()
}
if (!res.ok) throw new Error(json?.message ?? 'Request failed')
@@ -73,7 +65,7 @@ async function renterFetch<T>(path: string, init?: RequestInit): Promise<T> {
}
export function clearRenterSession() {
window.localStorage.removeItem('renter_token')
void fetch(`${API_BASE}/auth/renter/logout`, { method: 'POST', credentials: 'include' })
}
export function loadRenterProfile() {