refactor: consolidate custom widget admin routes
This commit is contained in:
1 parent
48438fc003
commit
74fa51a461
8 files changed
+72
-73
No files matched your search
@@ -2,10 +2,14 @@ import { NextResponse } from "next/server";
|
||||
|
||||
import { auth } from "@homarr/auth/next";
|
||||
|
||||
export const requireCustomWidgetAdmin = async (): Promise<NextResponse | null> => {
|
||||
const session = await auth();
|
||||
if (!session?.user.permissions.includes("admin")) {
|
||||
return NextResponse.json({ error: "Administrator access is required." }, { status: 403 });
|
||||
}
|
||||
return null;
|
||||
};
|
||||
type RouteHandler<Arguments extends unknown[]> = (...args: Arguments) => Response | Promise<Response>;
|
||||
|
||||
export const adminRoute =
|
||||
<Arguments extends unknown[]>(handler: RouteHandler<Arguments>) =>
|
||||
async (...args: Arguments): Promise<Response> => {
|
||||
const session = await auth();
|
||||
if (!session?.user.permissions.includes("admin")) {
|
||||
return NextResponse.json({ error: "Administrator access is required." }, { status: 403 });
|
||||
}
|
||||
return handler(...args);
|
||||
};
|
||||
Reference in new issue
Block a user