2.0: Invalid field error when trying to create additional tenant manually
jackadair opened this issue · 4 comments
I have succeeded in creating my user and root tenant however, when trying to create further tenants I am receiving a unauthorized error on the parent
field:
ERROR (payload): ValidationError: The following field is invalid: parent
at beforeChange (/home/node/app/node_modules/payload/src/fields/hooks/beforeChange/index.ts:56:11)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at create (/home/node/app/node_modules/payload/src/collections/operations/create.ts:197:31)
at createHandler (/home/node/app/node_modules/payload/src/collections/requestHandlers/create.ts:26:17)
Dependencies:
{
"dependencies": {
"@aws-sdk/client-s3": "^3.427.0",
"@aws-sdk/lib-storage": "^3.427.0",
"@payloadcms/bundler-webpack": "^1.0.3",
"@payloadcms/db-mongodb": "^1.0.3",
"@payloadcms/plugin-cloud": "^0.0.10",
"@payloadcms/plugin-cloud-storage": "^1.0.19",
"@payloadcms/richtext-lexical": "^0.1.5",
"cross-env": "^7.0.3",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"payload": "^2.0.13",
"payload-tenancy": "^2.0.0"
},
It is also a required field so I can't create any additional tenants.
Any help appreciated!
Screencap
Screen.Recording.2023-10-26.at.3.35.05.PM.mov
I can't reproduce this. I need some more help to figure out what might be the problem.
The "Unauthorized" validation error triggers when selected parent is some tenant that user has no access to. Access to the tenant depends on what tenant the current user belongs to. The tenant user belongs in and all tenants under that are authorized for that user.
Normally the parent field won't list tenants that user don't have access to, because tenants collection limits read access to only documents that are authorized for the user. So it's weird that this happens at all.
@joas8211 Thanks for taking a look, I just dropped by database to try again and can reproduce under the following conditions:
- Enable plugin like so:
plugins: [
tenancy()
]
- Create initial user manually using the Admin UI
- Create root tenant manually using Admin UI
- After creating root tenant, I receive the following error in my docker console:
[20:22:32] WARN (payload): rollbackTransaction called when no transaction exists
[20:22:32] ERROR (payload): NotFound: The requested resource was not found.
at findByID (/home/node/app/node_modules/payload/src/collections/operations/findByID.ts:109:15)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at findByIDHandler (/home/node/app/node_modules/payload/src/collections/requestHandlers/findByID.ts:19:17)
- At this stage my admin UI will not load, to remedy this, I enable the path based isolation strategy with:
plugins: [
tenancy({
isolationStrategy: "path"
)
]
- I can now see all my collections at the path based url
localhost:3000/tenant-slug/admin
. - Try to create a child tenant which is where I encounter the previously reported validation error
Maybe there's just some setup that I've missed...I will also try to do the programmatic setup as written in the docs see if that changes anything.
I tried to replicate with the latest blank template + Lexical running in Docker using docker-compose.yml provided in the template, and still no luck. You have some other dependencies listed so I assume you have some project you are working on instead of trying this out in isolation. So, is it possible that your code is using transactions but not resolving them? The following warning you provided is indicating something like that.
[20:22:32] WARN (payload): rollbackTransaction called when no transaction exists
@joas8211 Finally found my issue, it was due to my code but i'll leave this here if anyone else comes across it:
auth: {
depth: 0,
},
instead of:
auth: true
Had it left over from Payloads docs about creating multi-tenancy before I found your plugin.
Thanks again for taking a look!