Files
dashboards/apps/business/src/services/authService.ts
T
Alireza HassaniandCursor aeaad0f645 Improve auth UX and password strength across dashboards.
Remove business self-registration, localize SMS/auth errors, add password strength + confirm on reset/signup, and brand customer role as website user. Also include websites SSL sync UI updates.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-08 23:29:55 +03:30

86 lines
2.2 KiB
TypeScript

import { apiRequest, setTokens, clearTokens } from '../lib/api'
import { clearActiveBusiness } from '../lib/businessContext'
import type {
AuthUser,
LoginResponse,
MeResponse,
OtpSendResponse,
OtpVerifyResponse,
} 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 fetchCurrentUser(signal?: AbortSignal) {
return apiRequest<MeResponse>('/auth/me', { auth: true, signal })
}
export async function sendOtp(cellNumber: string, domain?: string) {
return apiRequest<OtpSendResponse>('/auth/send-otp', {
method: 'POST',
body: domain ? { cellNumber, domain } : { cellNumber },
})
}
export async function verifyOtp(cellNumber: string, code: string) {
return apiRequest<OtpVerifyResponse>('/auth/verify-otp', {
method: 'POST',
body: { cellNumber, code },
})
}
export async function loginWithOtp(cellNumber: string, code: string) {
const data = await apiRequest<LoginResponse>('/auth/login-otp', {
method: 'POST',
body: { cellNumber, code },
})
setTokens(data.accessToken, data.refreshToken)
return data
}
export async function resetPassword(cellNumber: string, code: string, newPassword: string) {
return apiRequest<{ message: string }>('/auth/reset-password', {
method: 'POST',
body: { cellNumber, code, newPassword },
})
}
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()
}