phpsymfonyjwtlexikjwtauthbundle

Symfony Lexik Authentication with Phone Number


I'm currently working on a Symfony project where I need to implement registration using email/password or only a phone number and OTP without any password. I'm using the Lexik bundle for authentication, but I'm facing some challenges since Lexik requires an email and password for token generation.

How can I modify the registration process to handle phone number and OTP only, and still be able to generate a token without an email and password? Any suggestions or code examples would be greatly appreciated.

Thank you in advance for your help.


Solution

  • You can generate tokens programmatically with LexikJWTAuthenticationBundle: see the documentation here.

    public function getTokenUser(UserInterface $user, JWTTokenManagerInterface $JWTManager)
    {
        // ...
    
        return new JsonResponse(['token' => $JWTManager->create($user)]);
    }