refactor(api): 🚚 Change ApiRouteMetadata structure to be more consistent

This commit is contained in:
Jesse Wierzbinski 2024-06-13 18:03:17 -10:00
parent 00fd751c2a
commit 924ff9b2d4
No known key found for this signature in database
3 changed files with 8 additions and 3 deletions

View file

@ -25,7 +25,10 @@ export const meta = applyConfig({
route: "/api/v1/statuses/:id",
auth: {
required: false,
requiredOnMethods: ["DELETE", "PUT"],
methodOverrides: {
DELETE: true,
PUT: true,
},
},
permissions: {
required: [RolePermissions.ViewNotes],

View file

@ -13,7 +13,9 @@ export interface ApiRouteMetadata {
route: string;
auth: {
required: boolean;
requiredOnMethods?: HttpVerb[];
methodOverrides?: {
[Key in HttpVerb]?: boolean;
};
oauthPermissions?: string[];
};
permissions?: {

View file

@ -158,7 +158,7 @@ const checkRouteNeedsAuth = (
);
}
if (authData.requiredOnMethods?.includes(context.req.method as HttpVerb)) {
if (authData.methodOverrides?.[context.req.method as HttpVerb]) {
return context.json(
{
error: "Unauthorized",