How to refresh the fos_user token every time a user submits a reset request?

50 Views Asked by At

Every time a user sends a reset resetting/request with email or username I need to refresh the token how to refresh the token

I need to generate a new token (which sends to email).

What configuration setting in configs is responsible for saying: every password recovery request - generate a new password

1

There are 1 best solutions below

0
Lenny4 On

Here is a Controller to create a new token from a user.

Please look at this doc for more informations https://github.com/lexik/LexikJWTAuthenticationBundle/blob/2.x/Resources/doc/7-manual-token-creation.rst#creating-jwt-tokens-programmatically

<?php

namespace App\Controller\User;

use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\JsonResponse;

class ResetTokenController extends AbstractController
{
    public function __invoke(Security $security, JWTTokenManagerInterface $JWTTokenManager): JsonResponse
    {
        $user = $security->getUser();
        $token = $JWTTokenManager->create($user);
        return new JsonResponse(['token' => $token]);
    }
}