MCPcopy
hub / github.com/joschan21/digitalhippo / isAdminOrHasAccess

Function isAdminOrHasAccess

src/collections/Products/Products.ts:54–79  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52
53const isAdminOrHasAccess =
54 (): Access =>
55 ({ req: { user: _user } }) => {
56 const user = _user as User | undefined
57
58 if (!user) return false
59 if (user.role === 'admin') return true
60
61 const userProductIDs = (user.products || []).reduce<
62 Array<string>
63 >((acc, product) => {
64 if (!product) return acc
65 if (typeof product === 'string') {
66 acc.push(product)
67 } else {
68 acc.push(product.id)
69 }
70
71 return acc
72 }, [])
73
74 return {
75 id: {
76 in: userProductIDs,
77 },
78 }
79 }
80
81export const Products: CollectionConfig = {
82 slug: 'products',

Callers 1

Products.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected