-
-
Notifications
You must be signed in to change notification settings - Fork 167
-
-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User.txt session refresh issue after $user->update #2486
Comments
It should be $user = $user->update(['subscribe' => $variable]); Kirby objects are immutable but return the altered object. So you have to put it back in your variable. |
Ok, but then my snippet / included in the default template returns Whoops \ Exception \ ErrorException (E_NOTICE) in the snippet how to update kirby()->user(); itsef? |
@hroma Can you share all the codes in snippet? I think you have diffrent problem. |
Thank you for investigating the issue. $user = kirby()->user();
if ($user->subscribe() == 'true') {
echo 'true';
} else {
echo 'false';
} Controller: return function ($site, $pages, $page) {
$kirby = kirby();
if ($kirby->request()->is('POST')) {
$variable = get('newsletter');
$user = $kirby->user('user@email.com');
$user = $user->update(['newsletter' => $variable]);
}
return array('user' => $user);
} Template: echo $user->newsletter().' - ';
snippet('subscribe.php'); Result:
Expected:
If you refresh the browser (F5)…???:
|
Yes now I can reproduce the issue. After updating the user, the |
We need to override trait UserActions
{
public function update(array $input = null, string $language = null, bool $validate = false)
{
$user = parent::update($input, $language, $validate);
// set auth user data only if the current user is this user
if ($user->isLoggedIn() === true) {
$this->kirby()->auth()->setUser($user);
}
return $user;
}
} |
Great. It is working well now. Thank you for your fast support |
@hroma I have updated the code on above comment: #2486 (comment) However, I recommend not using it production website unless PR is approved. |
✅ |
Passing $user = $user->update… to a template is working as expected but
when a user edit his data (user.txt) in the frontend, change stored (in a session?) aren't updated (snippet for my case).
CASE SCENARIO:
LoggedIn user can subscribe (true) or unsubscribe (false) to a newsletter on a toggle basis:
RESULT:
Old value: false
New value: false
EXPECTED:
Old value: false
New value: true
Did I miss Something to update the User globally or it is a bug?
Hope it helps making Kirby even better
The text was updated successfully, but these errors were encountered: