0

I'm trying to manually sign in a user.

Previously this was done calling $this->Auth->login()

I can't find how to do it using the Authentication plugin.

halfer
  • 19,824
  • 17
  • 99
  • 186
Robin.v
  • 719
  • 3
  • 8
  • 16
  • I think it's just the `setIdentity` call? Is there something that `login` does for you that this doesn't? – Greg Schmidt Jul 17 '20 at 14:04
  • Hi Greg, thank you for your reply. I believe this function uses the request data? I can’t seem to find an API description of the authentication component – Robin.v Jul 17 '20 at 18:53

2 Answers2

1

 $this->Authentication->setIdentity($this->request->getData());

https://github.com/cakephp/authentication/issues/370

IjIj
  • 23
  • 4
0

You can manually login users by doing the following Create an Entity of User by getting the user data you want to login. By using setUser, we can finally set the user and finally redirect him to the home page.

public function manualLogin()
{
    $user = $this->Users->newEntity($this->request->getData());
  
    $this->Auth->setUser($user->toArray());
    return $this->redirect(['controller' => 'Home','action' => 'index' ]);
}
Madhu Jayarama
  • 415
  • 1
  • 5
  • 15