- Create (public) route group with landing page (hero, featured listings, district links, stats, CTA) - Create search page with filter sidebar, list/map/split view modes, URL-synced filters, pagination - Build ListingMap component with CSS-based marker visualization and popup details - Build FilterBar with transaction type, property type, city, price range, area, bedrooms filters - Build PropertyCard and SearchResults components with responsive grid layout - Update middleware to allow public access to / and /search routes - Move dashboard home to /dashboard to avoid route conflict - All content in Vietnamese, mobile responsive Co-Authored-By: Paperclip <noreply@paperclip.ing>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import type { NextRequest } from 'next/server';
|
|
|
|
const publicPaths = ['/login', '/register', '/search'];
|
|
|
|
const publicExactPaths = ['/'];
|
|
|
|
export function middleware(request: NextRequest) {
|
|
const { pathname } = request.nextUrl;
|
|
|
|
const isPublicPath =
|
|
publicExactPaths.includes(pathname) ||
|
|
publicPaths.some((path) => pathname.startsWith(path));
|
|
|
|
// We check for the token cookie or rely on client-side auth store.
|
|
// For SSR-safe auth, check a lightweight cookie set by the client after login.
|
|
const hasAuthCookie = request.cookies.has('goodgo_authenticated');
|
|
|
|
if (!isPublicPath && !hasAuthCookie) {
|
|
const loginUrl = new URL('/login', request.url);
|
|
loginUrl.searchParams.set('redirect', pathname);
|
|
return NextResponse.redirect(loginUrl);
|
|
}
|
|
|
|
const isAuthOnlyPath = ['/login', '/register'].some((path) => pathname.startsWith(path));
|
|
if (isAuthOnlyPath && hasAuthCookie) {
|
|
return NextResponse.redirect(new URL('/dashboard', request.url));
|
|
}
|
|
|
|
return NextResponse.next();
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ['/((?!api|_next/static|_next/image|favicon.ico|public).*)'],
|
|
};
|