Skip to content

kolossi101/artwork-explorer-user-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User API

This is a Node.js-based RESTful API for managing user accounts, including user registration, login, and managing user-specific data such as favourites and history. The API uses MongoDB for data storage and JWT for authentication.

Features

  • User registration with password hashing
  • User login with JWT authentication
  • Manage user favourites (add, remove, retrieve)
  • Manage user history (add, remove, retrieve)
  • Secure API endpoints with Passport.js and JWT

Technologies Used

  • Node.js: Backend runtime
  • Express: Web framework
  • MongoDB: Database
  • Mongoose: MongoDB object modeling
  • bcryptjs: Password hashing
  • jsonwebtoken: JWT for authentication
  • Passport.js: Authentication middleware
  • dotenv: Environment variable management
  • CORS: Cross-origin resource sharing

Prerequisites

  • Node.js (v14 or higher)
  • MongoDB instance
  • Vercel CLI (optional, for deployment)

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd user-api
  2. Install dependencies:

    npm install
  3. Create a .env file in the root directory and add the following environment variables:

    MONGO_URL=<your-mongodb-connection-string>
    JWT_SECRET=<your-jwt-secret>
    PORT=<port-number> # Optional, defaults to 8080
  4. Start the server:

    npm start
  5. The API will be available at http://localhost:8080.

API Endpoints

Authentication

  • POST /api/user/register

    • Register a new user.
    • Request body:
    {
    "userName": "exampleUser",
    "password": "password123",
    "password2": "password123"
    }
  • POST /api/user/login - Login a user and receive a JWT token. - Request body: bash { "userName": "exampleUser", "password": "password123" }

Favourites

  • GET /api/user/favourites

    • Retrieve the user's favourites.
    • Requires JWT authentication.
  • PUT /api/user/favourites/:id

    • Add a favourite item.
    • Requires JWT authentication.
  • DELETE /api/user/favourites/:id

    • Remove a favourite item.
    • Requires JWT authentication.

History

  • GET /api/user/history Retrieve the user's history. Requires JWT authentication.

  • PUT /api/user/history/:id

    • Add a history item.
    • Requires JWT authentication.
  • DELETE /api/user/history/:id

    • Remove a history item.
    • Requires JWT authentication.

Please see artwork-explorer-app for an example of User API usage.

Deployment

This project can be deployed on Vercel for production. Follow the Next.js deployment documentation for more details.

Author: Nadiia Geras
Date: April 13, 2025

Releases

No releases published

Packages

No packages published