Add basic authentication

This commit is contained in:
2026-05-02 14:59:05 +02:00
parent e1c6ea9e51
commit f1fd72520a
15 changed files with 369 additions and 66 deletions
+6 -6
View File
@@ -1,8 +1,8 @@
import { makeApiUrl } from '.';
import { fetchWithAuth } from '.';
import type { CreateUserRequest, UpdateUserRequest, User } from './types/user';
export const getUsers = async (): Promise<User[]> => {
const response = await fetch(makeApiUrl('/users'), {
const response = await fetchWithAuth('/users', {
method: 'GET',
});
if (response.status === 404) {
@@ -15,7 +15,7 @@ export const getUsers = async (): Promise<User[]> => {
};
export const getUserById = async (id: string): Promise<User> => {
const response = await fetch(makeApiUrl(`/users/${id}`), {
const response = await fetchWithAuth(`/users/${id}`, {
method: 'GET',
});
if (!response.ok) {
@@ -25,7 +25,7 @@ export const getUserById = async (id: string): Promise<User> => {
};
export const createUser = async (data: CreateUserRequest): Promise<User> => {
const response = await fetch(makeApiUrl('/users'), {
const response = await fetchWithAuth('/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -39,7 +39,7 @@ export const createUser = async (data: CreateUserRequest): Promise<User> => {
};
export const updateUser = async (id: string, data: Partial<UpdateUserRequest>): Promise<User> => {
const response = await fetch(makeApiUrl(`/users/${id}`), {
const response = await fetchWithAuth(`/users/${id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
@@ -53,7 +53,7 @@ export const updateUser = async (id: string, data: Partial<UpdateUserRequest>):
};
export const deleteUser = async (id: string): Promise<void> => {
const response = await fetch(makeApiUrl(`/users/${id}`), {
const response = await fetchWithAuth(`/users/${id}`, {
method: 'DELETE',
});
if (!response.ok) {