跳转至

Authentication

These endpoints handle user registration, login, and profile retrieval.

POST /api/auth/register

  • Description: Registers a new user.
  • Request Body:
    {
      "studentId": "string",
      "username": "string",
      "password": "string"
    }
    
  • Response Body (Success):
    {
      "message": "Register Successful"
    }
    
  • Response Body (Failure):
    {
      "message": "Registration failed",
      "error": "string"
    }
    

POST /api/auth/login

  • Description: Logs in a user and returns a JWT token for subsequent authenticated requests.
  • Request Body:
    {
      "studentId": "string",
      "password": "string"
    }
    
  • Response Body (Success):
    {
      "token": "string",
      "user": {
        "studentId": "string",
        "username": "string"
      }
    }
    
  • Response Body (Failure):
    {
      "message": "Authentication failed",
      "error": "string"
    }
    

GET /api/auth/me

  • Description: Retrieves the profile of the currently authenticated user. Requires a valid JWT in the Authorization header.
  • Headers:
    • Authorization: Bearer <token>
  • Response Body (Success):
    {
      "studentId": "string",
      "username": "string"
    }
    
  • Response Body (Failure):
    {
      "message": "Unauthorized"
    }