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
Valid email address (must be a university email)
Password (minimum 6 characters)
User role: STUDENT, ORGANIZER, EVENT_ORGANIZER, or ADMIN
Contact phone number (optional)
Student-Specific Fields
Student ID (e.g., “S123456”) - required for STUDENT role
Student’s major/field of study
Current year of study (1-4)
Organizer-Specific Fields
Name of the organization - required for ORGANIZER role
Department or faculty affiliation
Admin-Specific Fields
Administrative level (optional, defaults are applied)
Response
HTTP status code (201 for successful registration)
Registration response data (may include JWT token)
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
Validation Error (400)
Email Already Exists (409)
{
"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
User’s registered email address
Response
HTTP status code (200 for successful login)
Authentication data including JWT token
JWT access token for authenticated requests
User’s role in the system
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
Invalid Credentials (401)
Account Suspended (403)
{
"statusCode" : 401 ,
"message" : "Invalid email or password" ,
"timestamp" : "2024-03-07T10:30:00"
}
For all protected endpoints, include the JWT token in the Authorization header:
Authorization : Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...