Skip to content

Commit ac5d861

Browse files
committed
added example to AuthenticationSuccessHandler::onAuthenticationSuccess
1 parent ba39a48 commit ac5d861

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

security/login_link.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,14 @@ First create the ``AuthenticationSuccessHandler``::
671671

672672
class AuthenticationSuccessHandler implements AuthenticationSuccessHandlerInterface
673673
{
674-
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
674+
public function onAuthenticationSuccess(Request $request, TokenInterface $token): JsonResponse
675675
{
676-
// ...
676+
// Example use case: Create API token for Guard Authentication.
677+
$user = $token->getUser(); // Returns string|\Stringable|UserInterface - depends on your implementation.
678+
679+
$userApiToken = $user->getApiToken();
680+
681+
return new JsonResponse(['apiToken' => 'userApiToken']);
677682
}
678683
}
679684

0 commit comments

Comments
 (0)