Skip to content

TwoMindsOneCode/Task-Management-API-with-User-Authentication

Repository files navigation

Task Management API

Overview

This is a task management API built using Node.js, Express, SQLite3, and JWT for authentication. The API allows user registration, login, task management (CRUD operations), and role-based access control (Admin and Normal User).

Features

  • User Registration: New users can register by providing a username, password, email, and phone number.
  • Login: Users can log in using their email and password to receive a JWT token.
  • Task Management:
    • Admins can create, read, update, and delete tasks.
    • Normal users can mark tasks as pending or done.
  • Role-Based Access Control: Admins have higher privileges than normal users.
  • JWT Authentication: Secures API routes and allows only authenticated users to perform actions.

Technologies Used

  • Node.js: JavaScript runtime.
  • Express.js: Web framework for Node.js.
  • SQLite3: Database for storing users and tasks.
  • JWT: JSON Web Token for authentication and securing routes.
  • bcryptjs: For hashing and verifying passwords.

Demonstration Video

Project Overview

Installation

To get started with the project, follow these steps:

  1. Clone the repository:
    git clone <repository-url>
  2. Navigate to the project directory:
    cd task-management-api
  3. Install the dependencies:
    npm install
  4. Create a .env file in the root directory and add the following environment variables:
    PORT=6060
    DB_PATH=./database/db.sqlite3
    JWT_SECRET=your_jwt_secret_key
  5. Run the database migration to create the necessary tables:
    npm run migrate
  6. Start the server:
    npm start

The API should now be running at http://localhost:6060.

Authentication & Authorization

JWT Token is required for all endpoints except /register and /login. Admins can perform CRUD operations on tasks. Normal users can only mark tasks as pending or done.

Database

The API uses SQLite3 to store user and task data. You can modify the database path in the .env file as needed.

User Table Schema

Field Type Description
id INT Primary Key (Auto Increment)
username TEXT Unique Username
password TEXT Hashed password
email TEXT Unique Email
phone TEXT Unique Phone Number
role TEXT User role (admin/normal user)

Task Table Schema

Field Type Description
id INT Primary Key (Auto Increment)
title TEXT Task title
description TEXT Task description
status TEXT Task status (pending/done)

Future Improvements

  • Add pagination for tasks.
  • Implement search and filtering by task status.
  • Improve error handling and validation.

License

This project is open-source and available under the MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •