This project implements a simple Todo API with CRUD operations, user authentication, and PostgreSQL as the database.
- User registration, login, logout, password reset, and forgot password functionality
- CRUD operations on todo items
- User authentication via JWT tokens
- Secure password storage with bcrypt
- Test coverage with Jest and Supertest
- Node.js and npm installed
- PostgreSQL installed and running
-
Clone the repository:
git clone https://github.com/Abiodun001-world/todo-api.git
-
Install dependencies:
npm install
-
Set up the
.envfile with your environment variables:DB_USER=your_db_user DB_HOST=localhost DB_NAME=your_db_name DB_PASSWORD=your_db_password DB_PORT=5432 JWT_SECRET=your_jwt_secret
-
Create the database and tables by running:
node initDb.js
To start the server, run:
npm startThe API will be available at http://localhost:3000.
-
POST
/auth/signup: Register a new user- Request Body:
{ "name": "string", "email": "string", "password": "string" } - Response:
{ "message": "User registered successfully", "token": "JWT token" }
- Request Body:
-
POST
/auth/signin: Log in a user- Request Body:
{ "email": "string", "password": "string" } - Response:
{ "message": "User signed in successfully", "token": "JWT token" }
- Request Body:
-
POST
/auth/signout: Log out a user- Response:
{ "message": "User signed out successfully" }
- Response:
-
POST
/auth/reset-password: Reset a user's password (requires authentication)- Request Body:
{ "email": "string", "newPassword": "string" } - Response:
{ "message": "Password reset successfully" }
- Request Body:
-
POST
/auth/forgot-password: Send a password reset link to a user- Request Body:
{ "email": "string" } - Response:
{ "message": "Password reset link sent" }
- Request Body:
-
POST
/api/todos: Create a new todo (requires authentication)- Request Body:
{ "title": "string", "description": "string" } - Response:
{ "id": "number", "title": "string", "description": "string" }
- Request Body:
-
GET
/api/todos: Get all todos for the authenticated user- Response:
[ { "id": "number", "title": "string", "description": "string" } ]
- Response:
-
GET
/api/todos/:id: Get a specific todo by ID (requires authentication)- Response:
{ "id": "number", "title": "string", "description": "string" }
- Response:
-
PUT
/api/todos/:id: Update a todo by ID (requires authentication)- Request Body:
{ "title": "string", "description": "string" } - Response:
{ "id": "number", "title": "string", "description": "string" }
- Request Body:
-
DELETE
/api/todos/:id: Delete a todo by ID (requires authentication)- Response:
{ "message": "Todo deleted successfully" }
- Response:
To run tests, use:
npm test