feat(auth): Implemented Session Persistence
This commit is contained in:
27
apps/web/src/features/dashboard/RoleDashboardRedirect.tsx
Normal file
27
apps/web/src/features/dashboard/RoleDashboardRedirect.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import React, {useEffect} from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { getDashboardPath } from '../../services/firestoreService'
|
||||
import type { RootState } from '../../store/store';
|
||||
/**
|
||||
* RoleDashboardRedirect Component
|
||||
* Dynamically redirects users to their appropriate dashboard based on their role
|
||||
*/
|
||||
export const RoleDashboardRedirect: React.FC = () => {
|
||||
const { isAuthenticated, user } = useSelector((state: RootState) => state.auth);
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated) {
|
||||
navigate('/login', { replace: true });
|
||||
return;
|
||||
}
|
||||
|
||||
if (user?.userRole) {
|
||||
const dashboardPath = getDashboardPath(user.userRole);
|
||||
navigate(dashboardPath, { replace: true });
|
||||
}
|
||||
}, [isAuthenticated, user?.userRole, navigate]);
|
||||
|
||||
return null;
|
||||
};
|
||||
Reference in New Issue
Block a user