update middleware

This commit is contained in:
Nate Kelley 2025-03-10 09:09:44 -06:00
parent 770df9c1ff
commit 152845fe4b
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 23 additions and 17 deletions

View File

@ -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 <ClientRedirect to={newUserRoute} />;
}

View File

@ -4,7 +4,7 @@ import { BusterRoutes, createBusterRoute } from '@/routes';
export default function AppHomePage() {
permanentRedirect(
createBusterRoute({
route: BusterRoutes.APP_METRIC
route: BusterRoutes.APP_HOME
})
);

View File

@ -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();

View File

@ -30,7 +30,7 @@ export const signInWithEmailAndPassword = async ({
return redirect(
createBusterRoute({
route: BusterRoutes.APP_METRIC
route: BusterRoutes.APP_HOME
})
);
};