feat(auth): implement WebOTP SMS auto-fill, auto-submit, password setup in dashboard, and password visibility toggle

This commit is contained in:
parsa aghaei committed 2026-08-16 16:37:59 +03:30
1 parent 897b4d61ec
commit cbd7e1a24d
6 files changed
+646 -265

No files matched your search

@@ -9,6 +9,9 @@ export interface User {
role: string;
walletBalance: number;
charityDonationTotal: number;
hasPassword?: boolean;
password?: string;
currentPassword?: string;
createdAt: string;
updatedAt: string;
pets?: unknown[];
+7 -3
View File
@@ -1,7 +1,7 @@
"use client";
import { create } from "zustand";
import { persist } from "zustand/middleware";
import { authService } from "../services/authService";
import { authService, User } from "../services/authService";
import api from "../services/api";
import { useCartStore } from "./cartStore";
import { usePetStore } from "./usePetStore";
@@ -37,6 +37,7 @@ interface UserProfile {
mobile: string;
walletBalance: number;
charityDonationTotal: number;
hasPassword?: boolean;
addresses: Address[];
transactions: Transaction[];
}
@@ -49,7 +50,7 @@ interface UserStore {
setRole: (role: UserRole) => void;
setLoggedIn: (isLoggedIn: boolean) => void;
setAuthModalOpen: (open: boolean) => void;
updateProfile: (profile: Partial<UserProfile>) => Promise<void>;
updateProfile: (profile: Partial<UserProfile & { password?: string; currentPassword?: string }>) => Promise<void>;
addAddress: (address: Address) => Promise<void>;
updateAddress: (id: string, address: Address) => Promise<void>;
deleteAddress: (id: string) => Promise<void>;
@@ -72,6 +73,7 @@ export const useUserStore = create<UserStore>()(
mobile: "",
walletBalance: 0,
charityDonationTotal: 0,
hasPassword: false,
addresses: [],
transactions: [],
},
@@ -80,7 +82,7 @@ export const useUserStore = create<UserStore>()(
setAuthModalOpen: (open) => set({ isAuthModalOpen: open }),
updateProfile: async (updates) => {
try {
const profileData = await authService.updateProfile(updates);
const profileData = await authService.updateProfile(updates as Partial<User>);
set((state) => ({
profile: {
...state.profile,
@@ -88,6 +90,7 @@ export const useUserStore = create<UserStore>()(
lastName: profileData.lastName,
email: profileData.email,
mobile: profileData.mobile || "",
hasPassword: profileData.hasPassword !== undefined ? profileData.hasPassword : state.profile.hasPassword,
}
}));
} catch (error) {
@@ -246,6 +249,7 @@ export const useUserStore = create<UserStore>()(
mobile: profileData.mobile || "",
walletBalance: backendWallet,
charityDonationTotal: backendCharity,
hasPassword: profileData.hasPassword !== undefined ? profileData.hasPassword : state.profile.hasPassword,
addresses: Array.isArray(pd.addresses) && pd.addresses.length > 0 ? (pd.addresses as Address[]) : state.profile.addresses,
transactions: backendTransactions.length > 0 ? backendTransactions : state.profile.transactions
}