I'm using SF 4 and this bundle. It's working fine. I'm using the suggested config:
firewalls:
login:
pattern: ^/api/login
stateless: true
anonymous: true
form_login:
check_path: /api/login_check
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
when I decode the token in the frontend I see it has the username, but it does not have the userId. Is there an easy way of adding the userId to the token?
You can listen for lexik_jwt_authentication.on_jwt_created event and attach the userId to token payload
public function onJwtCreated(JWTCreatedEvent $event): void
{
$user = $event->getUser();
$payload = $event->getData();
$payload['id'] = $user->getId();
$event->setData($payload);
}
Closing as explained
Most helpful comment
You can listen for
lexik_jwt_authentication.on_jwt_createdevent and attach the userId to token payload