Skip to main content
Lens Music uses JWT (JSON Web Token) authentication to secure API endpoints. This guide walks you through user registration, login, and using authentication tokens.

Prerequisites

Before you begin, ensure you have:
  • Access to the Lens Music API
  • A valid email address
  • A tool for making HTTP requests (curl, Postman, or similar)

User registration

Create a new user account by signing up with your email and password.
1

Prepare signup data

Gather the required information:
  • email: A valid email address
  • name: Your full name
  • password: A secure password
  • phone (optional): Your phone number
  • role (optional): User role (defaults to standard user)
2

Send signup request

Make a POST request to the signup endpoint:
POST /auth/signup
Content-Type: application/json

{
  "email": "[email protected]",
  "name": "John Doe",
  "password": "SecurePassword123!",
  "phone": "+1234567890"
}
curl -X POST https://api.lensmusic.com/auth/signup \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "name": "John Doe",
    "password": "SecurePassword123!"
  }'
3

Handle the response

On successful registration, you’ll receive:
{
  "message": "You have signed up successfully!",
  "data": {
    "user": {
      "id": "uuid-string",
      "email": "[email protected]",
      "name": "John Doe",
      "phone": "+1234567890",
      "role": "user"
    },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  }
}
Store the token securely. You’ll need it to authenticate future API requests.

User login

Authenticate existing users to obtain a JWT token.
1

Prepare login credentials

You only need two fields:
  • email: Your registered email address
  • password: Your account password
2

Send login request

Make a POST request to the login endpoint:
curl -X POST https://api.lensmusic.com/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "SecurePassword123!"
  }'
3

Receive authentication token

Successful login returns:
{
  "message": "You have logged in successfully!",
  "data": {
    "user": {
      "id": "uuid-string",
      "email": "[email protected]",
      "name": "John Doe",
      "role": "user"
    },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  }
}

Using authentication tokens

Once you have a JWT token, include it in the Authorization header for all protected endpoints.

Making authenticated requests

curl -X GET https://api.lensmusic.com/artists \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
All endpoints except /auth/signup and /auth/login require authentication. Requests without a valid token will return a 401 Unauthorized error.

Error handling

Handle common authentication errors gracefully:
{
  "message": "User already exists",
  "data": {
    "id": "existing-user-id",
    "email": "[email protected]"
  }
}
This occurs when trying to sign up with an email that’s already registered. Direct the user to login instead.
{
  "message": "Invalid email format"
}
Ensure the email follows standard format: [email protected]
{
  "message": "Invalid email or password"
}
The email or password is incorrect. Verify credentials and try again.
{
  "message": "Token expired"
}
The JWT token has expired. Login again to obtain a new token.

Best practices

Secure token storage

Store tokens in secure storage (e.g., httpOnly cookies, secure localStorage) and never expose them in URLs or logs.

Token refresh

Implement token refresh logic to maintain user sessions without requiring frequent re-authentication.

Password strength

Enforce strong password requirements: minimum 8 characters with uppercase, lowercase, numbers, and symbols.

Error handling

Provide clear error messages to users while avoiding security information disclosure.

Next steps

Managing artists

Create and manage artist profiles

Creating labels

Set up record labels for your releases

Build docs developers (and LLMs) love