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() {
+
-
+
}
/>
+
-
+
}
/>
+
-
+
}
/>
-
+ {/*
+
+
+
+ }
+ />
+ */}
+
-
- }
- />
+
+ } />
+ {/* /> */}
+ {/* */}