Skip to content

Authentication Example

v1.1.0

This guide demonstrates the complete JWT authentication flow generated by the package.


Authentication Flow

LoginJWT GuardAccess TokenProtected API

Login

POST /api/auth/login

Request:

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/me

Header:

text
Authorization: Bearer TOKEN

Returns the authenticated user.


Refresh Token

POST /api/auth/refresh

Returns a new JWT while invalidating the previous one.


Logout

POST /api/auth/logout

Invalidates the current token.


Internal Login Flow

text
Request

LoginRequest

JWT Guard

Token

JSON Response

The 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.

Released under the MIT License.