mirror of
https://git.meshkee.com/Meshkee/dashboards.git
synced 2026-08-11 22:30:58 +04:30
Add a real user profile page with multi-address CRUD, localize business profile, fix RTL category tree and login/sidebar logo fallbacks, and keep pagination controls centered with aligned page meta. Co-authored-by: Cursor <cursoragent@cursor.com>
87 lines
2.0 KiB
TypeScript
87 lines
2.0 KiB
TypeScript
import { apiRequest, setTokens, clearTokens } from '../lib/api'
|
|
import { clearActiveBusiness } from '../lib/businessContext'
|
|
import type {
|
|
AuthUser,
|
|
LoginResponse,
|
|
MeResponse,
|
|
OtpSendResponse,
|
|
OtpVerifyResponse,
|
|
RegisterResponse,
|
|
} from '../types/auth'
|
|
|
|
export async function login(cellNumber: string, password: string) {
|
|
const data = await apiRequest<LoginResponse>('/auth/login', {
|
|
method: 'POST',
|
|
body: { cellNumber, password },
|
|
})
|
|
|
|
setTokens(data.accessToken, data.refreshToken)
|
|
return data
|
|
}
|
|
|
|
export async function register(input: {
|
|
cellNumber: string
|
|
password: string
|
|
firstName: string
|
|
lastName: string
|
|
email?: string
|
|
domain: string
|
|
}) {
|
|
const data = await apiRequest<RegisterResponse>('/auth/register', {
|
|
method: 'POST',
|
|
body: input,
|
|
})
|
|
|
|
setTokens(data.accessToken, data.refreshToken)
|
|
return data
|
|
}
|
|
|
|
export async function fetchCurrentUser(signal?: AbortSignal) {
|
|
return apiRequest<MeResponse>('/auth/me', { auth: true, signal })
|
|
}
|
|
|
|
export async function sendOtp(cellNumber: string) {
|
|
return apiRequest<OtpSendResponse>('/auth/send-otp', {
|
|
method: 'POST',
|
|
body: { cellNumber },
|
|
})
|
|
}
|
|
|
|
export async function verifyOtp(cellNumber: string, code: string) {
|
|
return apiRequest<OtpVerifyResponse>('/auth/verify-otp', {
|
|
method: 'POST',
|
|
body: { cellNumber, code },
|
|
})
|
|
}
|
|
|
|
export async function changePassword(currentPassword: string, newPassword: string) {
|
|
return apiRequest<{ message: string }>('/auth/change-password', {
|
|
method: 'POST',
|
|
auth: true,
|
|
body: { currentPassword, newPassword },
|
|
})
|
|
}
|
|
|
|
export async function updateProfile(payload: {
|
|
firstName?: string
|
|
lastName?: string
|
|
firstNameEn?: string
|
|
lastNameEn?: string
|
|
email?: string | null
|
|
about?: string
|
|
instagram?: string
|
|
telegramId?: string
|
|
linkedin?: string
|
|
}) {
|
|
return apiRequest<{ message: string; user: AuthUser }>('/auth/profile', {
|
|
method: 'PATCH',
|
|
auth: true,
|
|
body: payload,
|
|
})
|
|
}
|
|
|
|
export function logout() {
|
|
clearTokens()
|
|
clearActiveBusiness()
|
|
}
|