🔑 Stateless Authentication (JWT)
The authentication flow is centralized in theAuthController, designed to be lightweight, secure, and fully adapted to language switching.
/api/v1/auth/login
Validates credentials and issues a signed JWT token if the user is active and correctly authenticated.
🛡️ Validation and Security Flow
- Credential Verification: Validates email and encrypted password using Laravel’s
Hashfacade. - Logical Deletion Protection: If the user exists but has been deactivated (Soft Delete), the system blocks access with a
403 Forbiddencode, preventing the token issuance. - Brute Force Prevention: The route is protected by a perimeter middleware (
throttle:4,1) that blocks the IP for one minute after 4 failed attempts.
🛂 Role-Based Access Control (RBAC)
Once the token is issued, authorization of protected routes is delegated to the customCheckRole middleware. This component intercepts requests, extracts the authenticated user’s profile, and dynamically verifies their privileges.
🚦 Interception Logic
The middleware leverages the Many-to-Many relationship between Eloquent’sUser and Role. It uses PHP’s native spread operator (...$roles) to receive a variable amount of allowed roles directly from the route definition.