Skip to main content
The MTB Backend API uses JWT (JSON Web Token) authentication powered by Strapi’s @strapi/plugin-users-permissions plugin. This guide covers user registration, login, and how to use JWT tokens in your API requests.

Authentication Flow

1

Register a new user

Create a new user account by providing username, email, and password
2

Login to get JWT token

Authenticate with your credentials to receive a JWT token
3

Use token in requests

Include the JWT token in the Authorization header for protected endpoints

Register a New User

Create a new user account by sending a POST request to the /api/auth/local/register endpoint.

Request

username
string
required
Unique username for the new user
email
string
required
Valid email address for the user
password
string
required
Password for the user account (minimum 6 characters)

Example Request

curl -X POST http://localhost:1337/api/auth/local/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "johndoe",
    "email": "[email protected]",
    "password": "SecurePass123!"
  }'

Response

jwt
string
JWT token for authentication
user
object
User information object
id
number
User ID
username
string
Username
email
string
User email address
provider
string
Authentication provider (default: “local”)
confirmed
boolean
Whether the user email is confirmed
blocked
boolean
Whether the user account is blocked
createdAt
string
Account creation timestamp
updatedAt
string
Last update timestamp
Example Response
{
  "jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNjMzMDI0MjAwLCJleHAiOjE2MzU2MTYyMDB9.K0HS7xKH0ZdXKJJh6gZCqZhVXjHqGq6x2r4M8qE5u8Y",
  "user": {
    "id": 1,
    "username": "johndoe",
    "email": "[email protected]",
    "provider": "local",
    "confirmed": false,
    "blocked": false,
    "createdAt": "2026-03-04T10:30:00.000Z",
    "updatedAt": "2026-03-04T10:30:00.000Z"
  }
}

Login

Authenticate with existing credentials to receive a JWT token.

Request

identifier
string
required
Username or email address
password
string
required
User password

Example Request

curl -X POST http://localhost:1337/api/auth/local \
  -H "Content-Type: application/json" \
  -d '{
    "identifier": "[email protected]",
    "password": "SecurePass123!"
  }'

Response

The response structure is identical to the registration response, containing the JWT token and user information.
Example Response
{
  "jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNjMzMDI0MjAwLCJleHAiOjE2MzU2MTYyMDB9.K0HS7xKH0ZdXKJJh6gZCqZhVXjHqGq6x2r4M8qE5u8Y",
  "user": {
    "id": 1,
    "username": "johndoe",
    "email": "[email protected]",
    "provider": "local",
    "confirmed": false,
    "blocked": false,
    "createdAt": "2026-03-04T10:30:00.000Z",
    "updatedAt": "2026-03-04T10:30:00.000Z"
  }
}

Using JWT Tokens in Requests

Once you have a JWT token, include it in the Authorization header of your requests to access protected endpoints.

Header Format

Authorization: Bearer YOUR_JWT_TOKEN

Example Authenticated Request

curl -X GET http://localhost:1337/api/users/me \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Get Current User

Retrieve the authenticated user’s information using the /api/users/me endpoint.

Example Request

cURL
curl -X GET http://localhost:1337/api/users/me \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Response

Example Response
{
  "id": 1,
  "username": "johndoe",
  "email": "[email protected]",
  "provider": "local",
  "confirmed": false,
  "blocked": false,
  "createdAt": "2026-03-04T10:30:00.000Z",
  "updatedAt": "2026-03-04T10:30:00.000Z"
}

Password Reset

Request a password reset email for a user account.

Request Password Reset

curl -X POST http://localhost:1337/api/auth/forgot-password \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]"
  }'

Reset Password with Code

After receiving the reset code via email, use it to set a new password:
curl -X POST http://localhost:1337/api/auth/reset-password \
  -H "Content-Type: application/json" \
  -d '{
    "code": "RESET_CODE_FROM_EMAIL",
    "password": "NewSecurePass123!",
    "passwordConfirmation": "NewSecurePass123!"
  }'

Error Responses

Authentication endpoints may return the following error responses:

400 Bad Request

{
  "error": {
    "status": 400,
    "name": "ValidationError",
    "message": "Email or Username are already taken",
    "details": {}
  }
}

401 Unauthorized

{
  "error": {
    "status": 401,
    "name": "UnauthorizedError",
    "message": "Invalid identifier or password",
    "details": {}
  }
}

403 Forbidden

{
  "error": {
    "status": 403,
    "name": "ForbiddenError",
    "message": "Your account has been blocked by an administrator",
    "details": {}
  }
}

Best Practices

Security Considerations
  • Always use HTTPS in production to protect JWT tokens in transit
  • Store JWT tokens securely (e.g., httpOnly cookies, secure storage)
  • Never expose tokens in URLs or logs
  • Implement token refresh mechanisms for long-lived sessions
  • Set appropriate token expiration times

Token Storage

  • Web Applications: Use httpOnly cookies or secure browser storage (localStorage with proper XSS protection)
  • Mobile Applications: Use secure storage mechanisms (iOS Keychain, Android Keystore)
  • Server-to-Server: Use environment variables or secure secret management systems

Token Expiration

JWT tokens issued by Strapi have a default expiration time. When a token expires, users must re-authenticate by calling the login endpoint again. To check if a token is expired, you’ll receive a 401 Unauthorized response:
{
  "error": {
    "status": 401,
    "name": "UnauthorizedError",
    "message": "Invalid token: Token expired",
    "details": {}
  }
}

Next Steps

API Endpoints

Explore available API endpoints

Quickstart

Get started with the MTB Backend API

Build docs developers (and LLMs) love