From f4080f75b78d9664249506b678f0e7b9f827b6b1 Mon Sep 17 00:00:00 2001 From: EETagent Date: Thu, 12 Jan 2023 13:19:09 +0100 Subject: [PATCH] feat: add admin whoami --- frontend/src/lib/@api/admin.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/frontend/src/lib/@api/admin.ts b/frontend/src/lib/@api/admin.ts index 6c9d64c..7972315 100644 --- a/frontend/src/lib/@api/admin.ts +++ b/frontend/src/lib/@api/admin.ts @@ -8,6 +8,22 @@ import type { import axios from 'axios'; import { API_URL, errorHandler, type Fetch } from '.'; +export const apiWhoami = async (fetchSsr?: Fetch): Promise => { + const apiFetch = fetchSsr || fetch; + try { + const res = await apiFetch(API_URL + '/admin/whoami', { + method: 'GET', + credentials: 'include' + }); + if (res.status != 200) { + throw Error(await res.text()); + } + return await res.json(); + } catch (e) { + throw errorHandler(e, 'Failed to fetch whoami'); + } +}; + // Login as admin /admin/login export const apiLogin = async (data: AdminLogin): Promise => { try {