feat: Redirect ADMIN and SUPER_ADMIN users from web app routes to the logout page.

This commit is contained in:
pradeepkumar
2026-03-20 17:05:15 +05:30
parent d5e3659ab2
commit 67317f86b5

View File

@@ -65,6 +65,14 @@ export default auth((req) => {
// Role-based route protection // Role-based route protection
if (isLoggedIn) { if (isLoggedIn) {
// Block ADMIN and SUPER_ADMIN from web app — they should use admin panel
if (userRole === "ADMIN" || userRole === "SUPER_ADMIN") {
// Allow logout and public routes
if (!isPublicRoute && !isNoRedirectRoute) {
return NextResponse.redirect(new URL("/logout", nextUrl.origin));
}
}
// Prevent regular users from accessing agent routes // Prevent regular users from accessing agent routes
if (isAgentRoute && userRole !== "AGENT") { if (isAgentRoute && userRole !== "AGENT") {
return NextResponse.redirect(new URL("/user/dashboard", nextUrl.origin)); return NextResponse.redirect(new URL("/user/dashboard", nextUrl.origin));