Hello,
I’m working on a page where users can register and can upload some information.
I think about how can I store user data because the user can be an author on more than one page and I need to activate or deactivate the user.
So I create a user-meta page. If the user registers a new account the Kirby creates a user and a new page adds the author for this page.
I did that with user.create:after hook.
But when I want to delete a user because it’s a bot or something else, I want to delete the meta-data too.
I tried to use the user.delete:before hook but I couldn’t delete the page from user-meta.
This is the code:
source:
'user.delete:before' => require __DIR__ . '/hooks/user_delete_before.php'
return function ($status, $user) {
$this->page('user-meta')
->childrenAndDrafts()
->filter(function($child) use($user) {
return $child->content()->username()->value() === $user->username();
})->delete();
}
I used the username field for
identification because $user->id() is my admin user id 
Someone have any idea what I did wrong?
Thank you in advance for your help.
Best,
Csaba
Hi Csaba,
I’m not sure if it’s actually necessary to create a seperate user-meta page when you could just add the fields for your user-meta-data to the user itself.
You could modify your user-blueprint to setup fields for all the metadata you need. Once you delete the user itself, these fields will then be deleted as well and there would be no need to keep a user-base in sync with an amount of user-meta pages.
Here is the guide to User blueprints
1 Like
Hi @rottstegge,
Thanks for the answer.
Yes, I know but I need a better view and list view of user data.
In the user-meta page, I want to list the author’s pages and In the user-meta I want to handle the active and reactive state.
In that case I would still go with the approach of having all the user relevant data (active/inactive) inside the user itself. To have a page that users can visit and that will show a user profile you could go with a custom route or a virtual page even. I think a similar problem was discussed here.
1 Like
I agree with @rottstegge.
Other than that, there is a problem with your code, your hook should look like this:
'user.delete:before' => function ($user) {
page('user-meta')
->childrenAndDrafts()
->findBy('username', $user->username())?->delete();
},
You were using filterBy()
, which returns a collection, not a single page, hence you cannot call delete()
.
1 Like
Thank you texnixe this solution is working! 
Dear @texnixe and @rottstegge,
I was thinking about what you wrote that the user-meta page is unnecessary.
You were right.
Finally, I wrote my own users area with Kirby components and their modifications.
This was the result:
Best,
Csaba