feat: Expo scaffold + auth screens + core screens (#39-#46, #48)

This commit is contained in:
Nemo
2026-03-23 18:40:04 +08:00
commit 745321e5bd
45 changed files with 10557 additions and 0 deletions

32
services/api.ts Normal file
View File

@@ -0,0 +1,32 @@
import axios from 'axios';
import * as SecureStore from 'expo-secure-store';
import { API_URL, STORAGE_KEYS } from '../constants';
export const api = axios.create({
baseURL: API_URL,
timeout: 15000,
headers: {
'Content-Type': 'application/json',
},
});
api.interceptors.request.use(async (config) => {
const token = await SecureStore.getItemAsync(STORAGE_KEYS.TOKEN);
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});
api.interceptors.response.use(
(response) => response,
async (error) => {
if (error.response?.status === 401) {
await SecureStore.deleteItemAsync(STORAGE_KEYS.TOKEN);
await SecureStore.deleteItemAsync(STORAGE_KEYS.USER);
}
return Promise.reject(error);
}
);
export default api;

43
services/auth.service.ts Normal file
View File

@@ -0,0 +1,43 @@
import api from './api';
export interface LoginPayload {
tenant_slug: string;
username: string;
password: string;
}
export interface LoginResponse {
token: string;
user: {
id: number;
name: string;
username: string;
email: string;
role: string;
tenant_slug: string;
};
}
export const authService = {
async checkTenantExists(slug: string): Promise<boolean> {
const res = await api.get(`/api/v1/auth/tenant/${slug}/exists`);
return res.data?.exists === true;
},
async login(payload: LoginPayload): Promise<LoginResponse> {
const res = await api.post('/api/v1/auth/login', payload);
return res.data;
},
async getProfile(): Promise<LoginResponse['user']> {
const res = await api.get('/api/v1/auth/me');
return res.data;
},
async changePassword(currentPassword: string, newPassword: string): Promise<void> {
await api.post('/api/v1/auth/change-password', {
current_password: currentPassword,
new_password: newPassword,
});
},
};