summaryrefslogtreecommitdiff
path: root/src/collections/Users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/collections/Users.ts')
-rw-r--r--src/collections/Users.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/collections/Users.ts b/src/collections/Users.ts
new file mode 100644
index 0000000..e7489ac
--- /dev/null
+++ b/src/collections/Users.ts
@@ -0,0 +1,40 @@
+import type { CollectionConfig } from "payload";
+
+export const Users: CollectionConfig = {
+ slug: "users",
+ admin: {
+ useAsTitle: "email",
+ },
+ auth: true,
+ access: {
+ read: ({ req: { user } }) => !!user,
+ create: ({ req: { user } }) => user?.role === "admin",
+ update: ({ req: { user }, id }) =>
+ user?.role === "admin" || user?.id === id,
+ delete: ({ req: { user } }) => user?.role === "admin",
+ },
+ fields: [
+ {
+ name: "role",
+ type: "select",
+ required: true,
+ defaultValue: "viewer",
+ options: [
+ { label: "Admin", value: "admin" },
+ { label: "Editor", value: "editor" },
+ { label: "Viewer", value: "viewer" },
+ ],
+ access: {
+ update: ({ req: { user } }) => user?.role === "admin",
+ },
+ },
+ {
+ name: "firstName",
+ type: "text",
+ },
+ {
+ name: "lastName",
+ type: "text",
+ },
+ ],
+};