diff --git a/web/src/app/app/layout.tsx b/web/src/app/app/layout.tsx index f7df92e04..27555be01 100644 --- a/web/src/app/app/layout.tsx +++ b/web/src/app/app/layout.tsx @@ -32,6 +32,12 @@ export default async function Layout({ pathname !== newUserRoute && !!accessToken //added to avoid bug with anon user ) { + console.log('redirecting to new user route', userInfo?.organizations?.[0]?.id); + console.log(userInfo?.user?.name); + console.log(cookiePathname); + console.log(pathname); + console.log(newUserRoute); + console.log(accessToken); return ; } diff --git a/web/src/app/app/page.tsx b/web/src/app/app/page.tsx index ead267b78..72232e6e5 100644 --- a/web/src/app/app/page.tsx +++ b/web/src/app/app/page.tsx @@ -4,7 +4,7 @@ import { BusterRoutes, createBusterRoute } from '@/routes'; export default function AppHomePage() { permanentRedirect( createBusterRoute({ - route: BusterRoutes.APP_METRIC + route: BusterRoutes.APP_HOME }) ); diff --git a/web/src/middleware.ts b/web/src/middleware.ts index 1631aad40..23349a1d6 100644 --- a/web/src/middleware.ts +++ b/web/src/middleware.ts @@ -1,22 +1,22 @@ import { NextResponse, type NextRequest } from 'next/server'; -// import { updateSession } from './middleware/supabaseMiddleware'; -// import { isPublicPage } from './middleware/publicPageMiddleware'; -// import { BusterRoutes, createBusterRoute } from './routes'; -// import { cspPolicyMiddleware } from './middleware/cspPolicyMiddleware'; -// import { nextPathnameMiddleware } from './middleware/nextPathnameMiddleware'; +import { updateSession } from './middleware/supabaseMiddleware'; +import { isPublicPage } from './middleware/publicPageMiddleware'; +import { BusterRoutes, createBusterRoute } from './routes'; +import { cspPolicyMiddleware } from './middleware/cspPolicyMiddleware'; +import { nextPathnameMiddleware } from './middleware/nextPathnameMiddleware'; export async function middleware(request: NextRequest) { try { - // const [supabaseResponse, user] = await updateSession(request); - // const performUserCheck = !isPublicPage(request); - // cspPolicyMiddleware(request); - // nextPathnameMiddleware(request, supabaseResponse); - // if (performUserCheck && !user && !request.nextUrl.pathname.includes('/test/')) { - // return NextResponse.redirect( - // new URL(createBusterRoute({ route: BusterRoutes.AUTH_LOGIN }), process.env.NEXT_PUBLIC_URL) - // ); - // } - // return supabaseResponse; + const [supabaseResponse, user] = await updateSession(request); + const performUserCheck = !isPublicPage(request); + cspPolicyMiddleware(request); + nextPathnameMiddleware(request, supabaseResponse); + if (performUserCheck && !user && !request.nextUrl.pathname.includes('/test/')) { + return NextResponse.redirect( + new URL(createBusterRoute({ route: BusterRoutes.AUTH_LOGIN }), process.env.NEXT_PUBLIC_URL) + ); + } + return supabaseResponse; } catch (error) { console.error('Error in middleware:', error); return NextResponse.next(); diff --git a/web/src/server_context/supabaseAuthMethods/signIn.ts b/web/src/server_context/supabaseAuthMethods/signIn.ts index cecfb4b3c..6fe697682 100644 --- a/web/src/server_context/supabaseAuthMethods/signIn.ts +++ b/web/src/server_context/supabaseAuthMethods/signIn.ts @@ -30,7 +30,7 @@ export const signInWithEmailAndPassword = async ({ return redirect( createBusterRoute({ - route: BusterRoutes.APP_METRIC + route: BusterRoutes.APP_HOME }) ); };