This commit is contained in:
rgrgogu
2026-06-24 13:43:28 +08:00
parent 93c3c688ca
commit b03b204861
35 changed files with 4238 additions and 2 deletions
+25
View File
@@ -0,0 +1,25 @@
// RequirePasswordChange.jsx
import { Navigate, Outlet } from 'react-router-dom'
import { useAuth } from '../contexts/AuthContext'
export default function RequirePasswordChange() {
const { user, loading } = useAuth()
if (loading) return null
// No user at all → send to login
if (!user) return <Navigate to="/login" replace />
// User is logged in but doesn't need to change password → send to dashboard
if (!user.must_change_password) {
switch (user.acc_type) {
case 'admin': return <Navigate to="/admin" replace />
case 'staff': return <Navigate to="/staff" replace />
case 'client': return <Navigate to="/client" replace />
default: return <Navigate to="/" replace />
}
}
// User is logged in AND must change password → allow through
return <Outlet />
}