Skip to content

Specification for API

Trần Vĩnh Phúc edited this page Oct 28, 2023 · 1 revision

API Specification

1. Register

POST /api/auth/register

Description: Register a new user with email, username, and password.

Request body:

{
    "email": "phuc.tranvinh13@hcmut.edu.vn",
    "password": "12345678",
    "confirmPassword": "12345678"
}

Request body constraints:

Field Type Constraints
email string Must be email format
password string Must be between 8 and 20 characters long
confirmPassword string Must be between 8 and 20 characters long

Optional query parameters: None

Response body:

{
    "statusCode": 201,
    "message": "Registered successfully, please check verification link in your email",
    "data": null
}

Response codes:

Status Code Message Description
201 Registered successfully Register successfully
400 Validation failed Validate request body with constraints and throw errors if any
400 Password do not match confirm password Password and confirm password don't match
400 User with this email already exists, please confirm your email User with this email already exists and account is not activated
400 User with this email already exists, please login User with this email already exists and account is activated

2. Login

POST /api/auth/login

Description: Login with email and password

Request body:

{
    "email" : "phuc.tranvinh13@hcmut.edu.vn",
    "password": "12345678"
}

Request body constraints:

Field Type Constraints
email string Must be email format
password string Must be between 8 and 20 characters long

Optional query parameters: None

Response body :

{
    "statusCode": 200,
    "message": "User logged in successfully",
    "data": {
        "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Im5nb2dpYXBob25nMzIxQGdtYWlsLmNvbSIsImlkIjoiY2xqcXZrMDhlMDAwMHNibDBpaHA4aTgzbCIsInJvbGUiOiJ1c2VyIiwiZGlzcGxheU5hbWUiOiJOZ28gR2lhIFBob25nIiwiYXZhdGFyIjoiaHR0cHM6Ly9jZG4uZGlzY29yZGFwcC5jb20vYXR0YWNobWVudHMvMTEyNjMyMTM3NTMzMDY5NzI3OC8xMTI2MzM3ODc3MjQwOTcxMzA0L2tpc3NwbmctbmluamEtY29tcHV0ZXItaWNvbnMtYXZhdGFyLXNhbXVyYWktYW5nbGUtNWI0NzkwZjZjMzk4OTEucG5nIiwic3RhdHVzIjoxLCJpYXQiOjE2ODg2NTE1MjYsImV4cCI6MTY4ODY1MTUzNn0.CfsH4jyZ84qr39YJoBjAYvjOqOyNxqQUPEn7weQrW80",
        "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Im5nb2dpYXBob25nMzIxQGdtYWlsLmNvbSIsImlkIjoiY2xqcXZrMDhlMDAwMHNibDBpaHA4aTgzbCIsInJvbGUiOiJ1c2VyIiwiZGlzcGxheU5hbWUiOiJOZ28gR2lhIFBob25nIiwiYXZhdGFyIjoiaHR0cHM6Ly9jZG4uZGlzY29yZGFwcC5jb20vYXR0YWNobWVudHMvMTEyNjMyMTM3NTMzMDY5NzI3OC8xMTI2MzM3ODc3MjQwOTcxMzA0L2tpc3NwbmctbmluamEtY29tcHV0ZXItaWNvbnMtYXZhdGFyLXNhbXVyYWktYW5nbGUtNWI0NzkwZjZjMzk4OTEucG5nIiwic3RhdHVzIjoxLCJpYXQiOjE2ODg2NTE1MjYsImV4cCI6MTY4ODczNzkyNn0.OFZu2r3WQqaH8CTAaR9SZJxpg2yGHz7vzOSyfresoo0",
        "user": {
            "id": "cljqvk08e0000sbl0ihp8i83l",
            "email": "phuc.tranvinh13@hcmut.edu.vn",
            "address": "KTX Khu A",
            "avatar": "https://cdn.discordapp.com/attachments/1126321375330697278/1126337877240971304/kisspng-ninja-computer-icons-avatar-samurai-angle-5b4790f6c39891.png",
            "role": "user",
            "AdafruitKey": "adakdasndkidh189212jkadaad",
        }
    }
}

Response codes:

Status Code Message Description
200 User logged in successfully Login successfully, return access token, refresh token and user info
400 Validation failed Validate request body with constraints and throw errors if any
400 Invalid credentials Invalid email or password

Clone this wiki locally