Authentication Documentation

This document covers all authentication-related endpoints and procedures for the Universal Bookshelf API.

Overview

The Universal Bookshelf API uses JWT (JSON Web Tokens) for authentication. All protected endpoints require a valid JWT token in the Authorization header.

Base URL

https://yourdomain.com/api

User Registration

POST /api/signup

Register a new user account

Request Body:
{
    "name": "John Doe",
    "email": "[email protected]",
    "password": "password123",
    "password_confirmation": "password123",
    "role": "reader"
}
Success Response (201):
{
    "status": true,
    "message": "User successfully registered",
    "user": {
        "id": 1,
        "name": "John Doe",
        "email": "[email protected]",
        "role": "reader",
        "email_verified_at": null,
        "created_at": "2024-01-01T00:00:00.000000Z",
        "updated_at": "2024-01-01T00:00:00.000000Z"
    },
    "authorization": {
        "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
        "type": "bearer"
    }
}
Error Response (422):
{
    "status": false,
    "message": "Validation error",
    "errors": {
        "email": ["The email has already been taken."],
        "password": ["The password confirmation does not match."]
    }
}

User Login

POST /api/login

Authenticate user and receive JWT token

Request Body:
{
    "email": "[email protected]",
    "password": "password123"
}
Success Response (200):
{
    "status": true,
    "message": "Login successful",
    "user": {
        "id": 1,
        "name": "John Doe",
        "email": "[email protected]",
        "role": "reader"
    },
    "authorization": {
        "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
        "type": "bearer"
    }
}
Error Response (401):
{
    "status": false,
    "message": "Invalid credentials"
}

User Logout

POST /api/logout

Logout user and invalidate token

Headers:
Authorization: Bearer <your_jwt_token>
Success Response (200):
{
    "status": true,
    "message": "Successfully logged out"
}

Refresh Token

POST /api/refresh

Refresh JWT token

Headers:
Authorization: Bearer <your_jwt_token>
Success Response (200):
{
    "status": true,
    "message": "Token refreshed successfully",
    "authorization": {
        "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
        "type": "bearer"
    }
}

Get User Profile

GET /api/user/profile

Get authenticated user's profile information

Headers:
Authorization: Bearer <your_jwt_token>
Success Response (200):
{
    "status": true,
    "user": {
        "id": 1,
        "name": "John Doe",
        "email": "[email protected]",
        "role": "reader",
        "email_verified_at": "2024-01-01T00:00:00.000000Z",
        "created_at": "2024-01-01T00:00:00.000000Z",
        "updated_at": "2024-01-01T00:00:00.000000Z"
    }
}

Update User Profile

PUT /api/user/profile

Update user profile information

Headers:
Authorization: Bearer <your_jwt_token>
Request Body:
{
    "name": "John Smith",
    "email": "[email protected]"
}
Success Response (200):
{
    "status": true,
    "message": "Profile updated successfully",
    "user": {
        "id": 1,
        "name": "John Smith",
        "email": "[email protected]",
        "role": "reader",
        "updated_at": "2024-01-01T00:00:00.000000Z"
    }
}

Change Password

PUT /api/user/change-password

Change user password

Headers:
Authorization: Bearer <your_jwt_token>
Request Body:
{
    "current_password": "oldpassword123",
    "new_password": "newpassword123",
    "new_password_confirmation": "newpassword123"
}
Success Response (200):
{
    "status": true,
    "message": "Password changed successfully"
}

Email Verification

POST /api/email/verification-notification

Resend email verification link

Headers:
Authorization: Bearer <your_jwt_token>
Success Response (200):
{
    "status": true,
    "message": "Verification link sent!"
}

Error Handling

Common HTTP Status Codes

  • 200 - Success
  • 201 - Created
  • 400 - Bad Request
  • 401 - Unauthorized
  • 403 - Forbidden
  • 404 - Not Found
  • 422 - Validation Error
  • 429 - Too Many Requests
  • 500 - Internal Server Error

Rate Limiting

Authentication endpoints are limited to 5 requests per minute per IP address. Exceeding this limit will result in a 429 response.

Need Help?

For additional support or questions about authentication, please contact our development team.

Back to Documentation