Skip to content

[FEAT]: Auth flow & Integration guide #36

Description

@AlMonther9

IEEE SVU - Backend API Documentation (Dev)

This document provides the necessary details for the frontend team to integrate with the User and Authentication endpoints.

Base URL (Development)

  • HTTP: http://localhost:5242
  • HTTPS: https://localhost:7135

Authentication Flow

The system uses JWT (JSON Web Token) for authentication.

  1. Login: Send credentials to the /api/User/login endpoint.
  2. Token: On success, you will receive a JWT string in the data field.
  3. Usage: For all protected endpoints, include the token in the Authorization header:
    Authorization: Bearer <your_token>

Important

Refresh Tokens: Not implemented. When a token expires (default 1 hour), the API returns 401 Unauthorized. The user must log in again.


Response Wrapper

All API responses follow a consistent wrapper format:

{
  "data": T,           // The actual response data (Object, String, or Boolean)
  "erroCode": 0,       // Internal error code (0 = No Error)
  "message": "...",    // Human-readable message
  "isSuccess": true    // Boolean indicating success
}

Endpoints

1. Register User

Create a new user account.

  • URL: /api/User/Register
  • Method: POST
  • Content-Type: multipart/form-data (Form Data)

Request Body (Fields):

Field Type Required Notes
FullName string Yes
Email string Yes Valid email format required
University string Yes
Password string Yes Min 6 characters
ConfirmPassword string Yes Must match Password
FacultyOrDepartment string No

Response (data):

  • boolean: true if registered successfully.

2. Login User

Authenticate and receive a JWT token.

  • URL: /api/User/login
  • Method: POST
  • Content-Type: application/json

Request Body (JSON):

{
  "email": "user@example.com",
  "password": "password123"
}

Response (data):

  • string: The JWT Access Token.

3. Get User Profile (Protected)

Retrieve the current authenticated user's profile information.

  • URL: /api/User/Profile
  • Method: GET
  • Authentication: Bearer Token Required

Response (data):

{
  "fullName": "John Doe",
  "imageUrl": "http://...",
  "email": "john@example.com",
  "phoneNumber": "0123456789",
  "university": "SVU",
  "faculty": "Engineering",
  "cv": "http://..."
}

4. Edit Profile (Protected)

Update profile details, including file uploads.

  • URL: /api/User/editprofile
  • Method: PUT
  • Authentication: Bearer Token Required
  • Content-Type: multipart/form-data (Form Data)

Request Body (Fields):

Field Type Required Notes
FullName string Yes
University string Yes
Faculty string Yes
PhoneNumber string No
Image File No Image file to upload
CV File No PDF/Doc file to upload
DeleteImage boolean No Set true to remove current image
DeleteCV boolean No Set true to remove current CV

Response (data):

  • boolean: true if updated successfully.

Error Codes

While isSuccess: false is the primary check, erroCode provides specific details:

  • 0: No Error
  • 1: Validation Error (Check message for details)
  • 2: Unauthorized
  • 3: Forbidden
  • 4: Not Found
  • 5: Internal Server Error
  • 6: Bad Request

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions