mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -1,6 +1,6 @@
|
||||
import { Navigate, Outlet } from 'react-router-dom'
|
||||
import { useAuth } from '../contexts/AuthContext'
|
||||
import { useEffect } from 'react'
|
||||
import { getRoleHomePath } from '../utils/roleRedirect.util'
|
||||
|
||||
export default function PublicRoute() {
|
||||
const { user, loading } = useAuth() // ← just loading and user
|
||||
@@ -8,12 +8,7 @@ export default function PublicRoute() {
|
||||
if (loading) return null // ← only block on initial cold load
|
||||
|
||||
if (user) {
|
||||
switch (user.acc_type) {
|
||||
case 'admin': return <Navigate to="/admin" replace />
|
||||
case 'user': return <Navigate to={user.needs_intro ? '/intro' : '/dashboard'} replace />
|
||||
case 'staff': return <Navigate to="/staff" replace />
|
||||
default: return <Navigate to="/dashboard" replace />
|
||||
}
|
||||
return <Navigate to={getRoleHomePath(user)} replace />
|
||||
}
|
||||
|
||||
return <Outlet />
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// RequirePasswordChange.jsx
|
||||
import { Navigate, Outlet } from 'react-router-dom'
|
||||
import { useAuth } from '../contexts/AuthContext'
|
||||
import { getRoleHomePath } from '../utils/roleRedirect.util'
|
||||
|
||||
export default function RequirePasswordChange() {
|
||||
const { user, loading } = useAuth()
|
||||
@@ -12,12 +13,7 @@ export default function RequirePasswordChange() {
|
||||
|
||||
// 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 />
|
||||
}
|
||||
return <Navigate to={getRoleHomePath(user)} replace />
|
||||
}
|
||||
|
||||
// User is logged in AND must change password → allow through
|
||||
|
||||
Reference in New Issue
Block a user