- Create app/ layer: App.tsx, providers, routing, layouts - Create entities/session/ for auth domain - Extract SessionProvider + AppProviders composition - Add ProtectedRoute, AppRoutes to app/routing/ - Add AppLayout to app/layouts/ - Convert legacy files to re-export shims - Update Login/Register/Profile pages to useSession
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { request, setAccessToken } from '@/shared/api/client';
|
|
import type { AuthResponse, UserResponse } from '@/shared/api/responses';
|
|
|
|
export async function login(email: string, password: string) {
|
|
const result = await request<AuthResponse>('/api/v1/auth/login', undefined, {
|
|
method: 'POST',
|
|
body: { email, password },
|
|
skipAuth: true,
|
|
});
|
|
setAccessToken(result.data.accessToken);
|
|
return result.data;
|
|
}
|
|
|
|
export async function register(email: string, password: string, name?: string) {
|
|
const result = await request<AuthResponse>('/api/v1/auth/register', undefined, {
|
|
method: 'POST',
|
|
body: { email, password, name },
|
|
skipAuth: true,
|
|
});
|
|
setAccessToken(result.data.accessToken);
|
|
return result.data;
|
|
}
|
|
|
|
export async function refresh() {
|
|
const result = await request<AuthResponse>('/api/v1/auth/refresh', undefined, {
|
|
method: 'POST',
|
|
skipAuth: true,
|
|
});
|
|
setAccessToken(result.data.accessToken);
|
|
return result.data;
|
|
}
|
|
|
|
export async function logout() {
|
|
const result = await request<{ message: string }>('/api/v1/auth/logout', undefined, {
|
|
method: 'POST',
|
|
});
|
|
setAccessToken(null);
|
|
return result.data;
|
|
}
|
|
|
|
export async function getMe() {
|
|
const result = await request<UserResponse>('/api/v1/auth/me');
|
|
return result.data;
|
|
}
|
|
|
|
export async function updateProfile(data: { name?: string }) {
|
|
const result = await request<UserResponse>('/api/v1/auth/me', undefined, {
|
|
method: 'PATCH',
|
|
body: data,
|
|
});
|
|
return result.data;
|
|
}
|