fix: ( backoffice ) accept phone or username in the login identifier field

This commit is contained in:
Abubeker Yasin
2026-08-18 11:28:10 +03:00
parent a9eac93fa3
commit 33100a31ae
2 changed files with 27 additions and 20 deletions

View File

@@ -18,7 +18,8 @@ interface AuthState {
token: string | null;
refreshToken: string | null;
isAuthenticated: boolean;
login: (email: string, password: string) => Promise<void>;
/** `identifier` may be an email, phone number or username — always sent as `email`. */
login: (identifier: string, password: string) => Promise<void>;
logout: () => void;
setUser: (user: AdminUser, token: string) => void;
initialize: () => void;
@@ -52,9 +53,10 @@ export const useAuthStore = create<AuthState>((set, get) => ({
}
},
login: async (email: string, password: string) => {
// Step 1: IAM login — returns token + refreshToken only
const loginRes = await axios.post(`${API_URL}/v1/auth/login`, { email, password });
login: async (identifier: string, password: string) => {
// Step 1: IAM login — returns token + refreshToken only.
// The IAM accepts an email, phone number or username in the `email` field.
const loginRes = await axios.post(`${API_URL}/v1/auth/login`, { email: identifier, password });
const loginData = loginRes.data?.data ?? loginRes.data;
const { token, refreshToken } = loginData;
if (!token) throw new Error('No token received from server');