Skip to content

Commit 8aaede1

Browse files
committed
Add auth redirect logic and clean up middleware path handling
1 parent 5e4863e commit 8aaede1

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

apps/app/src/app/[locale]/page.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
import { auth } from "@/utils/auth";
2+
import { headers } from "next/headers";
3+
import { redirect } from "next/navigation";
4+
15
export default async function RootPage() {
2-
return null;
6+
const session = await auth.api.getSession({
7+
headers: await headers(),
8+
});
9+
10+
if (!session) {
11+
return redirect("/auth");
12+
}
13+
14+
const orgId = session.session.activeOrganizationId;
15+
16+
if (!orgId) {
17+
return redirect("/setup");
18+
}
19+
20+
return redirect(`/${orgId}/implementation`);
321
}

apps/app/src/middleware.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ export async function middleware(request: NextRequest) {
2121
const nextUrl = request.nextUrl;
2222

2323
const pathnameLocale = nextUrl.pathname.split("/", 2)?.[1];
24+
2425
const pathnameWithoutLocale = pathnameLocale
2526
? nextUrl.pathname.slice(pathnameLocale.length + 1)
2627
: nextUrl.pathname;
28+
2729
const newUrl = new URL(pathnameWithoutLocale || "/", request.url);
2830

2931
response.headers.set("x-pathname", request.nextUrl.pathname);
@@ -32,9 +34,5 @@ export async function middleware(request: NextRequest) {
3234
return NextResponse.redirect(new URL("/auth", request.url));
3335
}
3436

35-
if (sessionCookie && newUrl.pathname === "/auth") {
36-
return NextResponse.redirect(new URL("/", request.url));
37-
}
38-
3937
return response;
4038
}

0 commit comments

Comments
 (0)