feat: update login functionality to remove refresh token and adjust password requirements
This commit is contained in:
@@ -30,6 +30,7 @@ export default function LoginPage() {
|
||||
const [forgotMobile, setForgotMobile] = useState('');
|
||||
const [forgotCode, setForgotCode] = useState('');
|
||||
const [forgotUuid, setForgotUuid] = useState('');
|
||||
const [forgotGrant, setForgotGrant] = useState('');
|
||||
const [forgotPass, setForgotPass] = useState('');
|
||||
const [forgotPass2, setForgotPass2] = useState('');
|
||||
const [showNewPass, setShowNewPass] = useState(false);
|
||||
@@ -71,7 +72,7 @@ export default function LoginPage() {
|
||||
});
|
||||
const json = await res.json();
|
||||
if (!res.ok) { toast.error(json?.errors?.[0]?.message ?? 'خطا در ورود'); return; }
|
||||
login(json.access_token, json.refresh_token ?? '');
|
||||
login(json.access_token);
|
||||
toast.success('خوش آمدید');
|
||||
} catch { toast.error('خطا در اتصال به سرور'); }
|
||||
finally { setPwLoading(false); }
|
||||
@@ -111,14 +112,16 @@ export default function LoginPage() {
|
||||
const vJson = await vRes.json();
|
||||
if (!vRes.ok) { toast.error(vJson?.errors?.[0]?.message ?? 'کد نادرست است'); return; }
|
||||
|
||||
const grant = vJson?.data?.grant;
|
||||
|
||||
const lRes = await fetch('/api/v1/user/otp-login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ uuid: smsUuid }),
|
||||
body: JSON.stringify({ grant }),
|
||||
});
|
||||
const lJson = await lRes.json();
|
||||
if (!lRes.ok) { toast.error(lJson?.errors?.[0]?.message ?? 'کاربری با این شماره یافت نشد'); return; }
|
||||
login(lJson.access_token, lJson.refresh_token ?? '');
|
||||
login(lJson.access_token);
|
||||
toast.success('خوش آمدید');
|
||||
} catch { toast.error('خطا در اتصال به سرور'); }
|
||||
finally { setSmsLoading(false); }
|
||||
@@ -140,20 +143,21 @@ export default function LoginPage() {
|
||||
});
|
||||
const json = await res.json();
|
||||
if (!res.ok) { toast.error(json?.errors?.[0]?.message ?? 'کد نادرست است'); return; }
|
||||
setForgotGrant(json?.data?.grant ?? '');
|
||||
setForgotStep(3);
|
||||
} catch { toast.error('خطا در اتصال به سرور'); }
|
||||
finally { setForgotLoading(false); }
|
||||
};
|
||||
|
||||
const handleForgotReset = async () => {
|
||||
if (forgotPass.length < 6) { toast.error('رمز عبور باید حداقل ۶ کاراکتر باشد'); return; }
|
||||
if (forgotPass.length < 8) { toast.error('رمز عبور باید حداقل ۸ کاراکتر باشد'); return; }
|
||||
if (forgotPass !== forgotPass2) { toast.error('رمزهای عبور یکسان نیستند'); return; }
|
||||
setForgotLoading(true);
|
||||
try {
|
||||
const res = await fetch('/api/v1/user/reset-password', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ uuid: forgotUuid, new_password: forgotPass }),
|
||||
body: JSON.stringify({ grant: forgotGrant, new_password: forgotPass }),
|
||||
});
|
||||
const json = await res.json();
|
||||
if (!res.ok) { toast.error(json?.errors?.[0]?.message ?? 'خطا در تغییر رمز'); return; }
|
||||
@@ -343,7 +347,7 @@ export default function LoginPage() {
|
||||
<label>رمز عبور جدید</label>
|
||||
<div style={{ position: 'relative' }}>
|
||||
<input className="input" type={showNewPass ? 'text' : 'password'}
|
||||
placeholder="حداقل ۶ کاراکتر" style={{ paddingLeft: 44 }}
|
||||
placeholder="حداقل ۸ کاراکتر" style={{ paddingLeft: 44 }}
|
||||
value={forgotPass} onChange={(e) => setForgotPass(e.target.value)} autoFocus />
|
||||
<button type="button" onClick={() => setShowNewPass((v) => !v)} style={{
|
||||
position: 'absolute', left: 12, top: '50%', transform: 'translateY(-50%)',
|
||||
|
||||
@@ -13,7 +13,6 @@ export interface ContextItem {
|
||||
|
||||
interface AuthState {
|
||||
token: string | null;
|
||||
refreshToken: string | null;
|
||||
isAuthenticated: boolean;
|
||||
userUuid: string | null;
|
||||
userName: string | null;
|
||||
@@ -24,7 +23,7 @@ interface AuthState {
|
||||
context: ContextItem | null;
|
||||
availableContexts: ContextItem[];
|
||||
|
||||
login: (token: string, refreshToken: string) => void;
|
||||
login: (token: string) => void;
|
||||
logout: () => void;
|
||||
fetchMe: () => Promise<void>;
|
||||
switchContext: (dbUuid: string) => Promise<void>;
|
||||
@@ -57,7 +56,6 @@ export const useAuthStore = create<AuthState>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
token: null,
|
||||
refreshToken: null,
|
||||
isAuthenticated: false,
|
||||
userUuid: null,
|
||||
userName: null,
|
||||
@@ -68,15 +66,14 @@ export const useAuthStore = create<AuthState>()(
|
||||
context: null,
|
||||
availableContexts: [],
|
||||
|
||||
login: (token, refreshToken) => {
|
||||
set({ token, refreshToken, isAuthenticated: true });
|
||||
login: (token) => {
|
||||
set({ token, isAuthenticated: true });
|
||||
get().fetchMe();
|
||||
},
|
||||
|
||||
logout: () =>
|
||||
set({
|
||||
token: null,
|
||||
refreshToken: null,
|
||||
isAuthenticated: false,
|
||||
userUuid: null,
|
||||
userName: null,
|
||||
@@ -128,7 +125,6 @@ export const useAuthStore = create<AuthState>()(
|
||||
name: 'clinicpro-auth',
|
||||
partialize: (s) => ({
|
||||
token: s.token,
|
||||
refreshToken: s.refreshToken,
|
||||
isAuthenticated: s.isAuthenticated,
|
||||
userUuid: s.userUuid,
|
||||
userName: s.userName,
|
||||
|
||||
Reference in New Issue
Block a user