Skip to content

Authentication API

Enables users to log in and out of the system.


Login Function

Users must provide a username and password to log in. Failed logins return error messages. Only registered users, employee and admin, can log in.

    POST /api/user/login
    Request:
    {
        "username": string
        "password": string
    }

Required fields: - Username (string) - Password (string)

    Response:
        Success: 200 Ok
        {
            message: "Logout successful",
            "user": 
                {
                    "user_id": 21,
                    "role_id": 2,
                    "role_name": "employee"
                }
        }

        Error: 401 Unauthorized
        {
            "error": "Invalid username or password"
        }

        Error 403 Forbidden
        {
            "error": "Account disabled. Please contact admin."
        }

        Error 404
        {
            "error": "Account not found."
        }

        Error 500
        {
            "error": "An unexpected error has occurred."
        }

Logout Function

Allows a logged-in user to log out of the system. Once logged out, the user will no longer have access until they log in again.

    POST /api/user/logout
    Request:
    {
        "username": string
    }

Required fields: - Username (string)

    Response:
        Success: 200 Ok
        {
            message: "Logout successful"
        }

        Error: 401 Unauthorized
        {
            "error": "User not logged in"
        }

        Error 500
        {
            "error": "An unexpected error has occurred."
        }