+ {/* Welcome Section */}
+
+
+ Welcome, {session?.user?.name?.split(' ')[0] || 'User'}!
+
+
+ Your real estate journey starts here. Explore properties, connect with agents, and find your dream home.
+
+
+
+ {/* Quick Actions */}
+
+
+
+
Search Properties
+
Find your perfect home from thousands of listings
+
+
+
+
+
Find Agents
+
Connect with top real estate professionals
+
+
+
+
+
Saved Favorites
+
View your saved properties and searches
+
+
+
+ {/* Stats */}
+
+
+ {/* Featured Properties */}
+
+
+
Featured Properties
+
+
+
+
+ {/* Property Card Placeholder */}
+
+
+
No featured properties yet
+
+
+
+
+
+ {/* Recent Activity */}
+
+
Recent Activity
+
+
+
No recent activity
+
+ Start exploring properties to see your activity here
+
+
+
+
+ );
+}
diff --git a/src/app/page.tsx b/src/app/page.tsx
index 5d42ce7..960ec61 100644
--- a/src/app/page.tsx
+++ b/src/app/page.tsx
@@ -1,86 +1,43 @@
'use client';
-import { useSession, signOut } from 'next-auth/react';
-import Link from 'next/link';
+import { useSession } from 'next-auth/react';
+import { useRouter } from 'next/navigation';
+import { useEffect } from 'react';
export default function Home() {
- const { data: session } = useSession();
+ const { data: session, status } = useSession();
+ const router = useRouter();
+ useEffect(() => {
+ if (status === 'loading') return;
+
+ if (!session) {
+ router.replace('/login');
+ return;
+ }
+
+ // Redirect based on user role
+ const userRole = (session.user as any)?.role;
+
+ if (userRole === 'AGENT') {
+ router.replace('/agent/dashboard');
+ } else {
+ router.replace('/user/dashboard');
+ }
+ }, [session, status, router]);
+
+ // Loading state while determining redirect
return (
-
- {/* Header */}
-
-
-
- {/* Logo */}
-
-

-
-
- {/* User Menu */}
-
-
- Welcome, {session?.user?.name || session?.user?.email || 'User'}
-
-
-
-
-
-
-
- {/* Main Content */}
-
-
-
- Welcome to RE-QuestN
-
-
- Your real estate journey starts here. Explore properties, connect with agents, and find your dream home.
-
-
- {/* Quick Actions */}
-
-
-
-
Browse Properties
-
Explore thousands of listings in your area
-
-
-
-
-
Find Agents
-
Connect with top real estate professionals
-
-
-
-
-
Saved Favorites
-
View your saved properties and searches
-
-
-
-
+
+
+

+
+
Loading...
+
);
}
diff --git a/src/middleware.ts b/src/middleware.ts
index 4275cde..6b3631d 100644
--- a/src/middleware.ts
+++ b/src/middleware.ts
@@ -7,11 +7,15 @@ const publicRoutes = ["/login", "/signup", "/forgot-password", "/reset-password"
export default auth((req) => {
const { nextUrl } = req;
const isLoggedIn = !!req.auth;
+ const userRole = (req.auth?.user as any)?.role;
const isPublicRoute = publicRoutes.some(
(route) => nextUrl.pathname === route || nextUrl.pathname.startsWith(route + "/")
);
+ const isAgentRoute = nextUrl.pathname.startsWith("/agent");
+ const isUserRoute = nextUrl.pathname.startsWith("/user");
+
const isApiRoute = nextUrl.pathname.startsWith("/api");
const isStaticRoute = nextUrl.pathname.startsWith("/_next") ||
nextUrl.pathname.startsWith("/assets") ||
@@ -24,7 +28,11 @@ export default auth((req) => {
// Redirect logged-in users away from public routes (login, signup)
if (isLoggedIn && isPublicRoute) {
- return NextResponse.redirect(new URL("/", nextUrl.origin));
+ // Redirect to appropriate dashboard based on role
+ if (userRole === "AGENT") {
+ return NextResponse.redirect(new URL("/agent/dashboard", nextUrl.origin));
+ }
+ return NextResponse.redirect(new URL("/user/dashboard", nextUrl.origin));
}
// Redirect non-logged-in users to login page for protected routes
@@ -34,6 +42,19 @@ export default auth((req) => {
return NextResponse.redirect(loginUrl);
}
+ // Role-based route protection
+ if (isLoggedIn) {
+ // Prevent regular users from accessing agent routes
+ if (isAgentRoute && userRole !== "AGENT") {
+ return NextResponse.redirect(new URL("/user/dashboard", nextUrl.origin));
+ }
+
+ // Prevent agents from accessing user routes
+ if (isUserRoute && userRole === "AGENT") {
+ return NextResponse.redirect(new URL("/agent/dashboard", nextUrl.origin));
+ }
+ }
+
return NextResponse.next();
});