wip
This commit is contained in:
@@ -10,6 +10,7 @@ import { checkRequiresMultiFactorAuthentication } from '@kit/supabase/check-requ
|
||||
import { createMiddlewareClient } from '@kit/supabase/middleware-client';
|
||||
|
||||
import { middleware as medusaMiddleware } from '~/medusa/middleware';
|
||||
import { medusaRefreshSession, retrieveCustomer } from '@lib/data/customer';
|
||||
|
||||
const CSRF_SECRET_COOKIE = 'csrfSecret';
|
||||
const NEXT_ACTION_HEADER = 'next-action';
|
||||
@@ -126,14 +127,20 @@ async function adminMiddleware(request: NextRequest, response: NextResponse) {
|
||||
);
|
||||
}
|
||||
|
||||
const client = createMiddlewareClient(request, response);
|
||||
const userIsSuperAdmin = await isSuperAdmin(client);
|
||||
|
||||
// If user is not an admin, redirect to 404 page.
|
||||
if (!userIsSuperAdmin) {
|
||||
return NextResponse.redirect(new URL('/404', request.nextUrl.origin).href);
|
||||
try {
|
||||
await medusaRefreshSession();
|
||||
} catch (error) {
|
||||
console.error('Error refreshing Medusa session', error);
|
||||
}
|
||||
|
||||
const client = createMiddlewareClient(request, response);
|
||||
// const userIsSuperAdmin = await isSuperAdmin(client);
|
||||
|
||||
// // If user is not an admin, redirect to 404 page.
|
||||
// if (!userIsSuperAdmin) {
|
||||
// return NextResponse.redirect(new URL('/404', request.nextUrl.origin).href);
|
||||
// }
|
||||
|
||||
// in all other cases, return the response
|
||||
return response;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user