File size: 1,047 Bytes
5306da4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import apiClient from './apiClient';
export interface LoginCredentials {
email: string;
password: string;
}
export interface SignupCredentials {
email: string;
password: string;
name: string;
}
export interface AuthResponse {
user: {
id: string;
email: string;
name: string;
};
token: string;
}
export const authApi = {
login: async (credentials: LoginCredentials): Promise<AuthResponse> => {
const response = await apiClient.post<AuthResponse>('/auth/login', credentials);
return response.data;
},
signup: async (credentials: SignupCredentials): Promise<AuthResponse> => {
const response = await apiClient.post<AuthResponse>('/auth/signup', credentials);
return response.data;
},
logout: async (): Promise<void> => {
await apiClient.post('/auth/logout');
localStorage.removeItem('authToken');
},
getCurrentUser: async (): Promise<AuthResponse['user']> => {
const response = await apiClient.get<AuthResponse['user']>('/auth/me');
return response.data;
}
};
|