Authentication Example
v1.1.0This guide demonstrates the complete JWT authentication flow generated by the package.
Authentication Flow
Login
POST/api/auth/loginRequest:
json
{
"email": "john@example.com",
"password": "secret123"
}Response:
json
{
"type": "success",
"status": 200,
"data": {
"access_token": "...",
"token_type": "Bearer",
"expires_in": 3600
}
}Current User
GET/api/auth/meHeader:
text
Authorization: Bearer TOKENReturns the authenticated user.
Refresh Token
POST/api/auth/refreshReturns a new JWT while invalidating the previous one.
Logout
POST/api/auth/logoutInvalidates the current token.
Internal Login Flow
text
Request
↓
LoginRequest
↓
JWT Guard
↓
Token
↓
JSON ResponseThe generated Controller already handles invalid credentials using standardized error responses.
Common Error Responses
Invalid credentials:
json
{
"type": "error",
"status": 401
}Missing token:
json
{
"type": "error",
"status": 401
}Expired token:
json
{
"type": "error",
"status": 401
}Authentication endpoints follow the same response structure used across the entire package.