POST
/auth/login
Auth Required

User Login

Authenticate a user with username and password. Returns a JWT token that expires in 24 hours.

Rate Limit: 10 per minute

Request/Response Examples

Send username and password to authenticate.

JSON
{
    "username": "admin",
    "password": "Admin@123"
}

Successful authentication returns JWT token.

JSON
{
    "status": "success",
    "data": {
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
        "user": {
            "id": 1,
            "username": "admin",
            "email": "admin@hotel.com"
        },
        "expires_in": 86400
    },
    "code": 200
}

Code Examples

PHP - Login Example

PHP example for authentication

<?php
$api_url = "https://hotel.webninjaafrica.com/api";
$login_data = array("username" => "admin", "password" => "Admin@123");

$ch = curl_init($api_url . "/auth/login");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($login_data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));

$response = curl_exec($ch);
$data = json_decode($response, true);
curl_close($ch);

if ($data["status"] === "success") {
    $token = $data["data"]["token"];
    echo "Login successful! Token: " . $token;
}
?>
Python - Login

Python example for authentication

import requests

url = "https://hotel.webninjaafrica.com/api/auth/login"
payload = {
    "username": "admin",
    "password": "Admin@123"
}

response = requests.post(url, json=payload)
data = response.json()

if data["status"] == "success":
    token = data["data"]["token"]
    print("Login successful! Token: " + token)
else:
    print("Login failed: " + data["message"])
Node.js - Login

Node.js example for authentication

const axios = require("axios");

async function login() {
    try {
        const response = await axios.post("https://hotel.webninjaafrica.com/api/auth/login", {
            username: "admin",
            password: "Admin@123"
        });
        
        if (response.data.status === "success") {
            const token = response.data.data.token;
            console.log("Login successful! Token: " + token);
            return token;
        }
    } catch (error) {
        console.error("Login failed:", error.response?.data?.message || error.message);
    }
}

login();
cURL - Login

cURL example for authentication

curl -X POST https://hotel.webninjaafrica.com/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"Admin@123"}'