lots of changes
This commit is contained in:
@@ -8,14 +8,37 @@ import { NextResponse } from "next/server";
|
||||
|
||||
const isSignInPage = createRouteMatcher(["/auth"]);
|
||||
const isProtectedPage = createRouteMatcher([
|
||||
"/dashboard(.*)",
|
||||
"/app(.*)",
|
||||
"/onboarding(.*)",
|
||||
"/opportunities(.*)",
|
||||
]);
|
||||
|
||||
export default convexAuthNextjsMiddleware(async (request) => {
|
||||
const { pathname, search } = request.nextUrl;
|
||||
if (pathname === "/app" || pathname === "/app/") {
|
||||
return NextResponse.redirect(new URL(`/app/dashboard${search || ""}`, request.url));
|
||||
}
|
||||
const legacyRedirects: Record<string, string> = {
|
||||
"/dashboard": "/app/dashboard",
|
||||
"/search": "/app/search",
|
||||
"/inbox": "/app/inbox",
|
||||
"/settings": "/app/settings",
|
||||
"/data-sources": "/app/data-sources",
|
||||
"/help": "/app/help",
|
||||
"/leads": "/app/inbox",
|
||||
"/opportunities": "/app/search",
|
||||
};
|
||||
const legacyMatch = Object.keys(legacyRedirects).find((path) =>
|
||||
pathname === path || pathname.startsWith(`${path}/`)
|
||||
);
|
||||
if (legacyMatch) {
|
||||
const targetBase = legacyRedirects[legacyMatch];
|
||||
const suffix = pathname.slice(legacyMatch.length);
|
||||
const target = `${targetBase}${suffix}${search || ""}`;
|
||||
return NextResponse.redirect(new URL(target, request.url));
|
||||
}
|
||||
|
||||
if (isSignInPage(request) && (await isAuthenticatedNextjs())) {
|
||||
return nextjsMiddlewareRedirect(request, "/dashboard");
|
||||
return nextjsMiddlewareRedirect(request, "/app/dashboard");
|
||||
}
|
||||
if (isProtectedPage(request) && !(await isAuthenticatedNextjs())) {
|
||||
const nextUrl = new URL("/auth", request.url);
|
||||
|
||||
Reference in New Issue
Block a user