Can't update user using $kirby->user()->update

Hi,

I’m creating a new site where end-users have to log in and agree to the website terms before they can view the site. In the user blueprint I have a toggle field for agreeing to the terms and a controller for the agreement page which should set the toggle using:

$agreed = get('agreed');
 if ($agreed == True) {
    	$kirby->user()->update([
    		'terms' => true,
    	]);
    }

When a logged in user ticks a box on the acceptance form and presses submit.

However after pressing submit the debugger shows an error message of:

Kirby\Exception\PermissionException thrown with message "You are not allowed to update the user {user name}

Can anyone help me with this?

Thank you,

To perform actions like updating etc., authentication is required, i.e. either a user with the right rights needs to be logged in, or you have to use $kirby->impersonate():

Thank you for your help! I hadn’t realised the action was performed as if you were logged in as the user.

In the end, I changed the end-user blueprint to have permissions: user: true (so I didn’t have to impersonate a user) which also worked.