0a9588abb7
- Add pagination support to findAll (page, limit query params) - Add findByTemplateId method to service - Add GET /by-template/:templateId endpoint to controller - Service already includes CRUD for QuestionBank and QuestionBankItem
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { API_BASE_URL } from '../utils/constants';
|
|
import { apiClient } from './apiClient';
|
|
|
|
interface AuthResponse {
|
|
access_token: string;
|
|
}
|
|
|
|
export const authService = {
|
|
async login(username: string, password: string): Promise<AuthResponse> {
|
|
const language = localStorage.getItem('userLanguage') || 'ja';
|
|
const response = await fetch(`${API_BASE_URL}/auth/login`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-user-language': language,
|
|
},
|
|
body: JSON.stringify({ username, password }),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorData = await response.json();
|
|
throw new Error(errorData.message || 'Login failed');
|
|
}
|
|
|
|
return response.json();
|
|
},
|
|
|
|
|
|
|
|
async getProfile(token: string): Promise<any> {
|
|
const response = await apiClient.request('/auth/profile', {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorData = await response.json();
|
|
throw new Error(errorData.message || 'Failed to fetch profile');
|
|
}
|
|
|
|
return response.json();
|
|
},
|
|
};
|