mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-07 12:00:43 +00:00
feat: add admin whoami
This commit is contained in:
parent
f52673713f
commit
f4080f75b7
1 changed files with 16 additions and 0 deletions
|
|
@ -8,6 +8,22 @@ import type {
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { API_URL, errorHandler, type Fetch } from '.';
|
import { API_URL, errorHandler, type Fetch } from '.';
|
||||||
|
|
||||||
|
export const apiWhoami = async (fetchSsr?: Fetch): Promise<CreateCandidate> => {
|
||||||
|
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
|
// Login as admin /admin/login
|
||||||
export const apiLogin = async (data: AdminLogin): Promise<number> => {
|
export const apiLogin = async (data: AdminLogin): Promise<number> => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue