How to use setNamespace in multiple authentication?
Notice: This thread is very old.
- netteman
- Member | 125
Hi all,
I want to be able to tell between users who logged into my Admin module and users who logged into the Front module.
I added this code to the SignInFormFactory
$this->user->getStorage()->setNamespace('backend');
\Tracy\Debugger::barDump($this->user);
$form->onSuccess[] = function (Form $form, $values) use ($onSuccess) {
try {
$this->user->setExpiration($values->remember ? '14 days' : '20 minutes');
$this->user->login($values->username, $values->password);
//MY CODE
$this->user->getStorage()->setNamespace('backend');
\Tracy\Debugger::barDump($this->user);
//MY CODE
} catch (Nette\Security\AuthenticationException $e) {
$form->addError('The username or password you entered is incorrect.');
return;
}
$onSuccess();
};
When I dump $this->user the namespace is set to ‘backend’ but when I dump the logged user elsewhere, the namespace is set back to ''.
Could you tell me how to use the setNamespace to differentiate between logged users?
Thanks :)
- David Matějka
- Moderator | 6445
you have to set the namespace in your base presenter for backend (e.g. in startup) – so the setNamespace method will be called in every request