adjusted
This commit is contained in:
@@ -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 />
|
||||
}
|
||||
Reference in New Issue
Block a user