Revert "fixed resolution"

This reverts commit 43279bc5b7.
This commit is contained in:
Malini 2026-01-07 18:13:39 +05:30
parent 43279bc5b7
commit ecc994299c

View File

@ -40,18 +40,12 @@ const RequireRole = ({ allowedRoles = [], children }) => {
return <Navigate to="/index" replace />; return <Navigate to="/index" replace />;
}; };
// ProtectedRoute component to check authentication and OTP verification // New ProtectedRoute component to check OTP verification
const ProtectedRoute = ({ children, allowedRoles = [] }) => { const ProtectedRoute = ({ children, allowedRoles = [] }) => {
const location = useLocation(); const location = useLocation();
const token = localStorage.getItem('token');
const isOTPVerified = localStorage.getItem('isOTPVerified') === 'true'; const isOTPVerified = localStorage.getItem('isOTPVerified') === 'true';
const userRole = localStorage.getItem('user_role') || ''; const userRole = localStorage.getItem('user_role') || '';
// If no token, redirect to login
if (!token) {
return <Navigate to="/index" state={{ from: location.pathname }} replace />;
}
// Check if user has the required role // Check if user has the required role
const hasRequiredRole = allowedRoles.some(role => const hasRequiredRole = allowedRoles.some(role =>
role.toLowerCase() === userRole.toLowerCase() role.toLowerCase() === userRole.toLowerCase()
@ -62,18 +56,23 @@ const ProtectedRoute = ({ children, allowedRoles = [] }) => {
return <Navigate to="/index" replace />; return <Navigate to="/index" replace />;
} }
// For all users, check OTP verification // For Admin users, no OTP check needed
// Skip OTP check for the OTP verification page itself if (userRole.toLowerCase() === 'admin') {
if (!location.pathname.includes('/verify-otp')) { return children;
// If OTP not verified, redirect to OTP verification }
if (!isOTPVerified) {
// For Establishment users, check OTP verification
if (userRole.toLowerCase() === 'establishmentuser' || userRole.toLowerCase() === 'establishment') {
if (!isOTPVerified && !location.pathname.includes('/verify-otp')) {
// Store the intended URL for redirecting after OTP verification // Store the intended URL for redirecting after OTP verification
localStorage.setItem('redirectAfterOTP', location.pathname); localStorage.setItem('redirectAfterOTP', location.pathname);
return <Navigate to="/index" replace />; return <Navigate to="/index" replace />;
} }
return children;
} }
return children; // Default redirect if no conditions are met
return <Navigate to="/index" replace />;
}; };
const SessionWarningModal = ({ show, remainingTime, onExtend, onLogout }) => { const SessionWarningModal = ({ show, remainingTime, onExtend, onLogout }) => {
@ -249,35 +248,44 @@ function App() {
<Route <Route
path="/admin/dashboard" path="/admin/dashboard"
element={ element={
<ProtectedRoute allowedRoles={['Admin']}> <RequireRole allowedRoles={['Admin']}>
<AdminDashboard /> <AdminDashboard />
</ProtectedRoute> </RequireRole>
} }
/> />
<Route <Route
path="/admin/validations" path="/admin/validations"
element={ element={
<ProtectedRoute allowedRoles={['Admin']}> <RequireRole allowedRoles={['Admin']}>
<Validations /> <Validations />
</ProtectedRoute> </RequireRole>
} }
/> />
<Route <Route
path="/admin/validations/:id" path="/admin/validations/:id"
element={ element={
<ProtectedRoute allowedRoles={['Admin']}> <RequireRole allowedRoles={['Admin']}>
<ValidationReview /> <ValidationReview />
</ProtectedRoute> </RequireRole>
} }
/> />
<Route {/* <Route path="/admin/configuration">
path="/admin/configuration/*" <Route
element={ index
<ProtectedRoute allowedRoles={['Admin', 'EstablishmentUser']}> element={
<RequireRole allowedRoles={['Admin', 'EstablishmentUser']}>
<Configuration />
</RequireRole>
}
/>
</Route> */}
<Route path="/admin/configuration/*" element={
<RequireRole allowedRoles={['Admin', 'EstablishmentUser']}>
<Configuration /> <Configuration />
</ProtectedRoute> </RequireRole>
} } />
/> {/* /> */}
{/* </Route> */}
<Route <Route
path="/manufacturing-index" path="/manufacturing-index"
element={ element={