feat: implement JWT authentication and authorization flow#164
feat: implement JWT authentication and authorization flow#164pranshugarg637 wants to merge 2 commits into
Conversation
Signed-off-by: Pranshu Garg <pranshunikhil2007@gmail.com>
|
@pranshugarg637 Please add the issue it closes. |
|
@Harxhit Pls help there is some issue |
|
@Harxhit After adding some of the features i tried to create a pull request but it is showing this |
There is nothing wrong with it. Please wait for the review process to be completed. |
|
Need some more time for this PR. Thanks! |
There was a problem hiding this comment.
Revert this file please.
| accentColor String @default("#6366f1") @map("accent_color") | ||
| provider String | ||
| providerId String @map("provider_id") | ||
| passwordHash String? @map("password_hash") |
There was a problem hiding this comment.
Why did you made it optional?
| const PASSWORD_SALT_ROUNDS = 12; | ||
|
|
||
| export async function authRoutes(app: FastifyInstance) { | ||
| app.post('/register', async (request: FastifyRequest, reply: FastifyReply) => { |
| } | ||
|
|
||
| const { email, username, displayName, password } = parsed.data; | ||
| const existingUser = await app.prisma.user.findFirst({ |
There was a problem hiding this comment.
Error handling can be better.
There was a problem hiding this comment.
Any breaks the type safety
| layer: 'api', | ||
| }, | ||
| }).catch(err => app.log.error('Failed to log follow:', err)); | ||
| }).catch((err: unknown) => app.log.error({ err }, 'Failed to log follow')); |
There was a problem hiding this comment.
Use instance off more better approach.


🚀 Overview
This PR implements a complete backend authentication and authorization flow for DevCard with secure authentication practices and protected route support.
✨ Features Added
👤 Authentication APIs
Implemented the following APIs:
POST /auth/registerPOST /auth/loginPOST /auth/logoutflow compatibility🛡️ Security Enhancements
Added secure backend authentication practices including:
bcrypt🔑 Authorization & Protected Routes
Implemented middleware and typing support for:
app.authenticateroute protection flow🗄️ Database Changes
Prisma Schema
Added:
passwordHashfield toUsermodelMigration
Created migration:
20260517000000_add_password_auth🧪 Test Coverage
Added authentication tests covering:
All backend tests and builds are passing successfully.
📁 Files Added / Updated
Updated Files
apps/backend/package.jsonapps/backend/prisma/schema.prismaapps/backend/src/routes/auth.tsapps/backend/src/routes/cards.tsapps/backend/src/routes/connect.tsapps/backend/src/routes/follow.tsapps/backend/src/routes/public.tsapps/backend/src/utils/validators.tsapps/backend/src/types/fastify.d.tspnpm-lock.yamlpnpm-workspace.yamlAdded Files
apps/backend/prisma/migrations/20260517000000_add_password_auth/migration.sqlapps/backend/src/__tests__/auth.test.ts✅ Verification