all repos — caroster @ v5.2

[Octree] Group carpool to your event https://caroster.io

backend/src/api/passenger/policies/add-only-self.ts (view raw)

 1import { errors } from "@strapi/utils";
 2
 3export default async (policyContext) => {
 4  const user = policyContext.state.user;
 5  const inputUserId = policyContext.args?.data?.user;
 6
 7  if (inputUserId) {
 8    if (user && `${user.id}` !== inputUserId)
 9      throw new errors.UnauthorizedError("Can't add another linked user");
10    else if (!user)
11      throw new errors.UnauthorizedError("Can't add linked user as anonymous");
12  }
13};