Add Playwright configuration and update codebase
The commit introduces Playwright configuration for End-to-End testing and modifies several files to optimize the project's structure. It also modifies the middleware to interact with Next.js and fix URL creation. Changes in database types were made to refine their structure.
This commit is contained in:
@@ -86,19 +86,20 @@ async function adminMiddleware(request: NextRequest, response: NextResponse) {
|
||||
|
||||
const supabase = createMiddlewareClient(request, response);
|
||||
const { data, error } = await supabase.auth.getUser();
|
||||
const host = request.nextUrl.host;
|
||||
|
||||
// If user is not logged in, redirect to sign in page.
|
||||
// This should never happen, but just in case.
|
||||
if (!data.user || error) {
|
||||
return NextResponse.redirect(`${host}/auth/sign-in`);
|
||||
return NextResponse.redirect(
|
||||
new URL(pathsConfig.auth.signIn, request.nextUrl.origin).href,
|
||||
);
|
||||
}
|
||||
|
||||
const role = data.user?.app_metadata.role;
|
||||
|
||||
// If user is not an admin, redirect to 404 page.
|
||||
if (!role || role !== 'super-admin') {
|
||||
return NextResponse.redirect(`${host}/404`);
|
||||
return NextResponse.redirect(new URL('/404', request.nextUrl.origin).href);
|
||||
}
|
||||
|
||||
// in all other cases, return the response
|
||||
|
||||
Reference in New Issue
Block a user