Skip to main content

Overview

The Authentication API provides endpoints for user registration and login. All authentication endpoints are public and do not require an access token.

Register User

curl -X POST https://api.example.com/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "firstName": "John",
    "lastName": "Doe",
    "email": "[email protected]",
    "password": "securePassword123",
    "role": "STUDENT",
    "studentID": "S123456",
    "major": "Computer Science",
    "yearOfStudy": 3
  }'
POST /api/auth/register
Content-Type: application/json
Register a new user in the system. The registration request varies based on the user role.

Request Body

firstName
string
required
User’s first name
lastName
string
required
User’s last name
email
string
required
Valid email address (must be a university email)
password
string
required
Password (minimum 6 characters)
role
enum
required
User role: STUDENT, ORGANIZER, EVENT_ORGANIZER, or ADMIN
phoneNumber
string
Contact phone number (optional)

Student-Specific Fields

studentID
string
Student ID (e.g., “S123456”) - required for STUDENT role
major
string
Student’s major/field of study
yearOfStudy
integer
Current year of study (1-4)

Organizer-Specific Fields

organizationName
string
Name of the organization - required for ORGANIZER role
departmentAffiliation
string
Department or faculty affiliation

Admin-Specific Fields

adminLevel
string
Administrative level (optional, defaults are applied)

Response

statusCode
integer
HTTP status code (201 for successful registration)
message
string
Success or error message
data
object
Registration response data (may include JWT token)
timestamp
string
ISO 8601 timestamp of the response
{
  "statusCode": 201,
  "message": "User registered successfully",
  "data": {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "userID": 1,
    "email": "[email protected]",
    "role": "STUDENT"
  },
  "timestamp": "2024-03-07T10:30:00"
}

Error Responses

{
  "statusCode": 400,
  "message": "Validation failed",
  "errors": [
    "Email should be valid",
    "Password must be at least 6 characters"
  ],
  "timestamp": "2024-03-07T10:30:00"
}

Login

curl -X POST https://api.example.com/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "securePassword123"
  }'
POST /api/auth/login
Content-Type: application/json
Authenticate a user and receive a JWT access token.

Request Body

email
string
required
User’s registered email address
password
string
required
User’s password

Response

statusCode
integer
HTTP status code (200 for successful login)
message
string
Success message
data
object
Authentication data including JWT token
data.token
string
JWT access token for authenticated requests
data.userID
integer
Unique user identifier
data.email
string
User’s email address
data.role
string
User’s role in the system
timestamp
string
ISO 8601 timestamp of the response
{
  "statusCode": 200,
  "message": "Login successful",
  "data": {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
    "userID": 1,
    "email": "[email protected]",
    "role": "STUDENT",
    "firstName": "John",
    "lastName": "Doe"
  },
  "timestamp": "2024-03-07T10:30:00"
}

Error Responses

{
  "statusCode": 401,
  "message": "Invalid email or password",
  "timestamp": "2024-03-07T10:30:00"
}

Authentication Header

For all protected endpoints, include the JWT token in the Authorization header:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Build docs developers (and LLMs) love