WHY: migrating from Supabase BaaS to self-hosted iloom backend (Go microservices) deployed on K3s. Supabase client and realtime subscriptions no longer applicable. HOW: - add src/api/ layer (client.ts, auth.ts, purchaser.ts, textile.ts, washing.ts, websocket.ts) targeting iloom-gateway REST endpoints - rewrite all hooks (usePlanData, useInventoryData, useDashboardData, useRealtime, etc.) to use new API client instead of Supabase queries - rewrite all page/component data fetching and mutations accordingly - delete src/supabase/client.ts, remove @supabase/supabase-js dep - add Dockerfile (multi-stage node build + nginx) and nginx.conf with reverse proxy to iloom-gateway for /api/ and /ws/ routes - adjust webpack.config.js for API_URL environment variable injection Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import { http, setAccessToken } from './client';
|
|
import type { Profile, Company, UserRole } from '../types';
|
|
|
|
export interface LoginRequest {
|
|
username: string;
|
|
password: string;
|
|
}
|
|
|
|
export interface LoginResponse {
|
|
access_token: string;
|
|
refresh_token: string;
|
|
user: Profile;
|
|
company: Company | null;
|
|
}
|
|
|
|
export interface RegisterRequest {
|
|
username: string;
|
|
password: string;
|
|
display_name: string;
|
|
company_name: string;
|
|
phone: string;
|
|
role: UserRole;
|
|
}
|
|
|
|
export interface MeResponse {
|
|
user: Profile;
|
|
company: Company | null;
|
|
}
|
|
|
|
export const authApi = {
|
|
login: async (data: LoginRequest) => {
|
|
const res = await http.post<LoginResponse>('/auth/login', data);
|
|
setAccessToken(res.data.access_token);
|
|
return res.data;
|
|
},
|
|
|
|
register: (data: RegisterRequest) =>
|
|
http.post<LoginResponse>('/auth/register', data).then(r => r.data),
|
|
|
|
logout: async () => {
|
|
await http.post('/auth/logout');
|
|
setAccessToken(null);
|
|
},
|
|
|
|
refresh: async () => {
|
|
const res = await http.post<{ access_token: string }>('/auth/refresh');
|
|
setAccessToken(res.data.access_token);
|
|
return res.data.access_token;
|
|
},
|
|
|
|
me: () => http.get<MeResponse>('/auth/me').then(r => r.data),
|
|
};
|