A simple authentication API providing secure user registration, JWT-based login, and protected route management. Built with Node.js, Prisma, and PostgreSQL.
- Node.js
- Express
- Prisma ORM (Database management)
- PostgreSQL
- JSON Web Token (JWT) (Secure authentication)
- bcrypt (Password hashing)
├── server.js
├── package.json
├── prisma/
│ └── schema.prisma
├── public/
│ ├── index.html
│ ├── style.css
│ └── script.js
└── src/ (Sugerido, ajuste conforme sua pasta real)
├── controllers/
├── middlewares/
├── routes/
└── utils/
- Node.js v18+
- PostgreSQL instance running
npm installCreate a .env file in the project root based on .env.example:
DATABASE_URL="postgresql://user:password@localhost:5432/authapi?schema=public"
JWT_SECRET="your_super_secret_key"# Generate the Prisma client
npx prisma generate
# Push the schema to your database
npx prisma db pushnpm run devThe server will be available at http://localhost:3000.
Creates a new user with a hashed password.
Request body:
{
"email": "user@example.com",
"password": "password123"
}Authenticates a user and returns a Bearer Token.
Response 200:
{
"token": "eyJhbGciOiJIUzI1..."
}A private route that requires a valid JWT in the headers.
Headers:
Authorization: Bearer your-jwt-tokenResponse 200:
{
"message": "Authenticated",
"userId": 1
}The project includes a minimal frontend located in the public/ folder.
⚠️ Note: The frontend is 100% vibe-coded and exists solely to facilitate quick API testing in the browser. The core focus of this repository is the backend implementation.
- Password Hashing: Uses
bcryptto ensure passwords are never stored in plain text. - JWT Authentication: Implements stateless authentication via tokens.
- Route Protection: Middleware logic to intercept and validate requests to private endpoints.


