Todo App with Auth

This is the best first MERN project.

It is small, but it touches the full stack.

Features

Backend routes

POST /api/auth/register
POST /api/auth/login
GET /api/auth/me
POST /api/todos
GET /api/todos
PATCH /api/todos/:id
DELETE /api/todos/:id

API contract examples

Create todo:

POST /api/todos

Request:

{
  "title": "Revise event loop"
}

Response:

{
  "data": {
    "id": "todo_1",
    "title": "Revise event loop",
    "completed": false
  }
}

List todos:

GET /api/todos

Response:

{
  "data": [
    {
      "id": "todo_1",
      "title": "Revise event loop",
      "completed": false
    }
  ]
}

MongoDB model

const todoSchema = new Schema({
  userId: { type: Schema.Types.ObjectId, ref: 'User', required: true },
  title: { type: String, required: true },
  completed: { type: Boolean, default: false },
}, { timestamps: true })

Important rule

Every todo query must include userId.

Bad:

Todo.findById(req.params.id)

Better:

Todo.findOne({ _id: req.params.id, userId: req.user.id })

Frontend screens

Build these screens:

Test scenarios

What this project proves