| Numéro du ticket | Titre du ticket | |------------------|-----------------| | #202 | Authentification — Connexion utilisateur (JWT) | ## Description de la PR [#202] Authentification — Connexion utilisateur (JWT) ## Modification du .env ## Check list - [x] Pas de régression - [ ] TU/TI/TF rédigée - [x] TU/TI/TF OK - [x] CHANGELOG modifié Reviewed-on: #5 Reviewed-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr> Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
28 lines
708 B
PHP
28 lines
708 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\State;
|
|
|
|
use ApiPlatform\Metadata\Operation;
|
|
use ApiPlatform\State\ProviderInterface;
|
|
use App\Entity\User;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
|
|
|
|
final readonly class MeProvider implements ProviderInterface
|
|
{
|
|
public function __construct(private Security $security) {}
|
|
|
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?object
|
|
{
|
|
$user = $this->security->getUser();
|
|
|
|
if (!$user instanceof User) {
|
|
throw new AccessDeniedException('User not authenticated.');
|
|
}
|
|
|
|
return $user;
|
|
}
|
|
}
|