namespace App\Repository;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Uid\Ulid;
use Webauthn\Bundle\Repository\PublicKeyCredentialUserEntityRepository as PublicKeyCredentialUserEntityRepositoryInterface;
use Webauthn\PublicKeyCredentialUserEntity;
final class PublicKeyCredentialUserEntityRepository implements PublicKeyCredentialUserEntityRepositoryInterface
* The UserRepository $userRepository is the repository
* that already exists in the application
public function __construct(private UserRepository $userRepository)
* This method creates the next Webauthn User Entity ID
* In this example, we use Ulid
public function generateNextUserEntityId(): string {
* This method saves the user or does nothing if the user already exists.
* It may throw an exception. Just adapt it on your needs
public function saveUserEntity(PublicKeyCredentialUserEntity $userEntity): void
/** @var User|null $user */
$user = $this->userRepository->findOneBy([
'id' => $userEntity->getId(),
if (!$user instanceof UserInterface) {
$userEntity->getUserIdentifier(),
$userEntity->getDisplayName() // Or any other similar method your entity may have
$this->userRepository->save($user); // Custom method to be added in your repository
public function findOneByUsername(string $username): ?PublicKeyCredentialUserEntity
/** @var User|null $user */
$user = $this->userRepository->findOneBy([
return $this->getUserEntity($user);
public function findOneByUserHandle(string $userHandle): ?PublicKeyCredentialUserEntity
/** @var User|null $user */
$user = $this->userRepository->findOneBy([
return $this->getUserEntity($user);
* Converts a Symfony User (if any) into a Webauthn User Entity
private function getUserEntity(null|User $user): ?PublicKeyCredentialUserEntity
return new PublicKeyCredentialUserEntity(
$user->getUserIdentifier(),