File size: 567 Bytes
7fc5208
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { API_BASE_URL,  handleResponse } from './util';

export interface LoginResponse {
    success: boolean;
    token: string;
    message?: string;
}

export const userApi = {
    async login(username: string, password: string): Promise<LoginResponse> {
        const response = await fetch(`${API_BASE_URL}/api/login`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({ username, password }),
        });
        return handleResponse(response);
    }
};