Answer the question
In order to leave comments, you need to log in
How to authorize a user immediately after registration?
Hello! Please tell me about the automatic login of the user immediately after registration.
Latest version of Symfony 5.2
I do as indicated in some examples on the Internet:
GuardAuthenticatorHandler $guardHandler,
LoginFormAuthenticator $formAuthenticator
And call:
$guardHandler->authenticateUserAndHandleSuccess(
$user,
$request,
$formAuthenticator,
'main'
);
The IDE and the code itself complain that $formAuthenticator does not inherit the \Symfony\Component\Security\Guard\AuthenticatorInterface interface.
What should be passed there then?
Answer the question
In order to leave comments, you need to log in
The answer turned out to be simple.
If you are using the new authorization system, then so be it.
/**
* Тест системы авторизации
*
* @Route("/test/", name="test")
*
* @param Request $request
* @param LoginFormAuthenticator $loginFormAuthenticator
* @param UserAuthenticatorInterface $userAuthenticator
*
* @return Response
* @throws ServiceException
*/
public function test(
Request $request,
LoginFormAuthenticator $loginFormAuthenticator,
UserAuthenticatorInterface $userAuthenticator
): Response
{
$user = $this->userService->getUserByEmail('[email protected]');
return $userAuthenticator->authenticateUser($user, $loginFormAuthenticator, $request);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question