Skip to content

VitaliiKhomiakov/Symfony_QuickStart_AuthJWT

Repository files navigation

Symfony 7 – Quick Start Auth JWT

Minimal JWT-auth starter based on Symfony 7.3, PHP 8.4+, LexikJWTAuthenticationBundle 3.x and Gesdinet JWT Refresh Token Bundle.

Stack

  • Backend: Symfony 7.3, PHP 8.4+
  • Security: LexikJWTAuthenticationBundle, Gesdinet JWT Refresh Token Bundle
  • DB / Web: MariaDB 11.4, Nginx (via Docker)

Run with Docker

docker compose up --build

API: http://127.0.0.1:8080.

Main endpoints

  • POST /auth/sign-up – register user
  • POST /api/login – get access + refresh tokens
  • POST /api/token/refresh – refresh access token
  • GET /api/user – current user (JWT required)
  • PATCH /api/user – admin-only (JWT + ROLE_ADMIN, user with this role must be created manually)

Useful console commands (inside container)

# default database
docker compose exec php php bin/console doctrine:database:create
docker compose exec php php bin/console doctrine:migrations:migrate

# test database (APP_ENV=test)
docker compose exec php php bin/console --env=test doctrine:database:create
docker compose exec php php bin/console --env=test doctrine:migrations:migrate

# cache and tests
docker compose exec php php bin/console cache:clear

# create test db before 
docker compose exec php ./vendor/bin/phpunit ds