File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { auth } from "@/utils/auth" ;
2+ import { headers } from "next/headers" ;
3+ import { redirect } from "next/navigation" ;
4+
15export 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments