From ecc994299c4273a68f5219a01108cae972a8a42a Mon Sep 17 00:00:00 2001 From: Malini Date: Wed, 7 Jan 2026 18:13:39 +0530 Subject: [PATCH] Revert "fixed resolution" This reverts commit 43279bc5b7a10a31d30b66d1f88d15ea990efdf3. --- ipi-survey-platform/src/App.jsx | 60 +++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/ipi-survey-platform/src/App.jsx b/ipi-survey-platform/src/App.jsx index 3189b72..6c812f6 100644 --- a/ipi-survey-platform/src/App.jsx +++ b/ipi-survey-platform/src/App.jsx @@ -40,18 +40,12 @@ const RequireRole = ({ allowedRoles = [], children }) => { return ; }; -// ProtectedRoute component to check authentication and OTP verification +// New ProtectedRoute component to check OTP verification const ProtectedRoute = ({ children, allowedRoles = [] }) => { const location = useLocation(); - const token = localStorage.getItem('token'); const isOTPVerified = localStorage.getItem('isOTPVerified') === 'true'; const userRole = localStorage.getItem('user_role') || ''; - // If no token, redirect to login - if (!token) { - return ; - } - // Check if user has the required role const hasRequiredRole = allowedRoles.some(role => role.toLowerCase() === userRole.toLowerCase() @@ -62,18 +56,23 @@ const ProtectedRoute = ({ children, allowedRoles = [] }) => { return ; } - // For all users, check OTP verification - // Skip OTP check for the OTP verification page itself - if (!location.pathname.includes('/verify-otp')) { - // If OTP not verified, redirect to OTP verification - if (!isOTPVerified) { + // For Admin users, no OTP check needed + if (userRole.toLowerCase() === 'admin') { + return children; + } + + // 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 localStorage.setItem('redirectAfterOTP', location.pathname); return ; } + return children; } - return children; + // Default redirect if no conditions are met + return ; }; const SessionWarningModal = ({ show, remainingTime, onExtend, onLogout }) => { @@ -249,35 +248,44 @@ function App() { + - + } /> + - + } /> + - + } /> - + {/* + + + + } + /> + */} + - - } - /> + + } /> + {/* /> */} + {/* */}