feat(auth): enhance access control in PrivateRoute and display error message in LoginPage

This commit is contained in:
hamed
2026-06-15 11:41:52 +03:30
parent 8c0b3d8282
commit 3d33cf09b8
2 changed files with 29 additions and 2 deletions
+13
View File
@@ -1,4 +1,5 @@
import React, { useEffect, useRef, useState } from 'react';
import { useSearchParams } from 'react-router-dom';
import { toast } from 'sonner';
import { EyeIcon, EyeSlashIcon } from '@heroicons/react/24/outline';
import { useAuthStore } from '../stores/authStore';
@@ -10,6 +11,7 @@ type ForgotStep = 1 | 2 | 3;
export default function LoginPage() {
const login = useAuthStore((s) => s.login);
const [searchParams] = useSearchParams();
const [mode, setMode] = useState<Mode>('password');
const [pwMobile, setPwMobile] = useState('');
@@ -186,6 +188,17 @@ export default function LoginPage() {
</p>
</div>
{searchParams.get('error') === 'access_denied' && (
<div style={{
background: '#fee2e2', border: '1px solid #fca5a5',
borderRadius: 8, padding: '10px 14px',
fontSize: 13, color: '#dc2626', marginBottom: 16,
textAlign: 'center',
}}>
حساب شما دسترسی به پنل مدیریت را ندارد
</div>
)}
{mode !== 'forgot' && (
<div style={{ display: 'flex', gap: 4, marginBottom: 24, background: 'var(--bg-2)', borderRadius: 10, padding: 4 }}>
{(['password', 'sms'] as const).map((m) => (