Back to Bricks

User Authentication

Auth & Security

Complete JWT-based authentication with register, login, logout, and protected routes middleware.

loginregisterjwtsecurity
Backend:Frontend:
prisma/schema.prismajavascript
1model User {
2 id String @id @default(uuid())
3 email String @unique
4 name String
5 password String
6 role String @default("user")
7 createdAt DateTime @default(now())
8}

Paste Guide

Copy files to:

prisma/schema.prisma (append models)repositories/auth.repo.jscontrollers/authController.jsroutes/authRoutes.js

Add to server.js:

app.use('/api/auth', require('./routes/authRoutes'));

Stack

PrismaExpressJWT

Test Examples

curl -X POST http://localhost:5000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"name": "John", "email": "john@example.com", "password": "123456"}'
curl -X POST http://localhost:5000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email": "john@example.com", "password": "123456"}'
curl http://localhost:5000/api/auth/me \
  -H "Authorization: Bearer YOUR_TOKEN"