Back to Bricks
User Authentication
Auth & SecurityComplete 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 @unique4 name String5 password String6 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.jsAdd 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"