Code to log user in after registration


Im trying to get a user to be logged into the Authentication componant automatically after they register. Ive tried looking for examples but cannot find any upto date.

im currently using CakePHP 4.x

if anyone can help that would be great.

Thank you for pointing me in the right direction.

Here is my code for anyone else that may have the same issue

	public function register()
		$user = $this->Users->newEmptyEntity();
        if ($this->request->is('post')) {
			$formdata = $this->request->getData();
			$formdata['role'] = 'user';
			$user = $this->Users->patchEntity($user, $formdata);
            if ($result = $this->Users->save($user)) {
				$this->Flash->success(__('The user has been saved.'));
                return $this->redirect(['action' => 'index']);
            $this->Flash->error(__('The user could not be saved. Please, try again.'));