Add a way to hide or restrict access to fields when creating the first user #2164
Replies: 4 comments 2 replies
-
|
My first thought is that you could use conditional logic on the field. // field
admin: {
condition: () => !window?.location?.includes('/create-first-user'),
}I haven't tested this yet, so you might need to play with it to get it to work. I would also name the function and assign it where you need for readability and reuse. Does that solve your issue? |
Beta Was this translation helpful? Give feedback.
-
|
What @DanRibbens wrote works. However you need to check if For my use case the first user page is located at {
name: "image",
type: "upload",
relationTo: "media",
admin: {
condition: () => {
if (typeof window !== "undefined") {
const path = window.location.pathname;
if (path === "/admin/create-first-user") {
return false;
}
return true
}
},
},
}, |
Beta Was this translation helpful? Give feedback.
-
|
Conditional rendering worked indeed. I was just being dumb. I somehow managed to mixup the fields and so tried to apply it to a wrong field of a wrong collection. Thanks for helping me @DanRibbens and @choutkamartin! |
Beta Was this translation helpful? Give feedback.
-
|
I also wanted to hide a field on first account creation and came across this discussion. Here's what I ended up doing that worked for me: admin: {
condition: (_data, _siblingData, { user }) => Boolean(user),
}, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm developing a multi-tenancy plugin for Payload CMS and I'd like to hide the tenant field from the setup form. Read more about the issue here: joas8211/payload-tenancy#1
Currently the form for creating the first user renders all fields in the collection + couble of hardcoded fields. It doesn't check field access, probably because it would fail anyway in most cases.
I can think of a few of possible solutions for this:
field.admin.setupboolean flag for the field to indicate if it's wanted to be shown at setup.field.admin.hiddenflag a function for conditional rendering.Beta Was this translation helpful? Give feedback.
All reactions