backend/src/api/vehicle/policies/check-creation.ts (view raw)
1import { errors } from "@strapi/utils";
2
3export default async (policyContext, config, { strapi }) => {
4 const user = policyContext.state.user;
5 if (!user)
6 throw new errors.ForbiddenError(
7 "Only authenticated user can create vehicle."
8 );
9
10 if (policyContext.args?.data?.user !== user.id)
11 throw new errors.UnauthorizedError(
12 "Can only create vehicle for authenticated user."
13 );
14};