This project is a secure, modular, and production-ready authentication system built with:
- Node.js
- Express
- Prisma ORM
- PostgreSQL
- HTTP-only secure cookies for session-based authentication
It provides a clean and scalable foundation for any web app that needs:
βοΈ User registration
βοΈ Login with session cookies
βοΈ Protected routes
βοΈ Token rotation
βοΈ Password hashing
βοΈ Environment-based configuration
βοΈ Safe DB access via Prisma
- Uses HTTP-only, Secure, and SameSite cookies
- Prevents XSS access to tokens
- Sessions work automatically with the browser
- No localStorage / JWT exposure
- Register new users
- Login with email/password
- Access protected routes using session cookies
- Logout by clearing cookies
- Bcrypt password hashing
- CSRF-safe cookie setup
- Prisma schema validation
- Optional Zod input validation
| Layer | Technology |
|---|---|
| Backend | Node.js + Express |
| ORM | Prisma |
| Database | PostgreSQL |
| Auth | Session cookies |
| Environment | dotenv |
| Hashing | bcryptjs |
| Deployment | Ready |
This repository serves as a starter template for building full web applications that require authentication without exposing JWT tokens.
It is:
- Beginner-friendly
- Clean and modular
- Structured for real-world usage
- Great for boosting your GitHub portfolio
- A strong backend base for any SaaS or dashboard
- Admin dashboards
- SaaS platforms
- Internal company tools
- Full-stack projects (React, Vue, Next.js)
- Mobile apps with API authentication
Below are all the main authentication routes, ready to test with Postman, Thunder Client, or cURL.
POST http://localhost:3000/auth/register
Content-Type: application/json
Example JSON body:
{
"email": "test@test.com",
"password": "mypassword"
}
π 2. Login (sets secure cookie)
POST http://localhost:3000/auth/login
Content-Type: application/json
Example JSON body:
{
"email": "test@test.com",
"password": "mypassword"
}
If login is successful:
A secure HTTP-only cookie will be automatically stored in your client
No need to manually copy tokens
Cookie is sent automatically with subsequent requests
π 3. Access Protected Route
GET http://localhost:3000/auth/me
Requirements:
Must send the cookie from login
Works automatically in browsers
In Postman: enable βSend Cookiesβ or use Cookie Jar
Example Response:
{
"id": 1,
"email": "test@test.com",
"createdAt": "2025-01-15T15:21:51.124Z"
}
π 4. Logout
POST http://localhost:3000/auth/logout
Behavior:
Clears the HTTP-only session cookie
After logout, /auth/me will return 401 Unauthorized