fix: Standardize API errors, add Vercel/Render deployment guide, secure JWT secrets#585
Merged
Wilfred007 merged 2 commits intoGildado:mainfrom Apr 22, 2026
Conversation
… deployment guide, secure JWT secrets ## Gildado#439 – Standardize API Error Response Format - Add src/utils/apiError.ts with apiErrorResponse() helper and ErrorCodes constants - All errors now return { code: string, message: string, details: unknown[] } - Update global 404 and 500 handlers in app.ts - Update authenticateJWT middleware to use standardized format - Update authController.ts (register, login, 2FA setup/verify/disable, refresh) - Update employeeController.ts (create, getAll, getOne, update, delete) - Update authController tests and employeeController tests to match new format - Add unit tests: src/utils/__tests__/apiError.test.ts (9 cases) ## Gildado#438 – Detailed Deployment Guide for Vercel/Render - Add DEPLOYMENT_GUIDE_CLOUD.md with step-by-step cloud hosting instructions - Covers: Vercel (frontend) + Render (backend + PostgreSQL + Redis) - Includes: environment variables table, CORS config, DB migrations, post-deploy checks - JWT secret rotation section with zero-downtime strategy - Troubleshooting section (CORS, DB connection, Render sleep tier) ## Gildado#457 – Secure JWT Keys with Environment Variables - Add src/utils/jwtSecurity.ts with validateJwtSecret() / checkJwtSecrets() / assertJwtSecretsSecure() - Server aborts at startup (process.exit(1)) when JWT_SECRET / JWT_REFRESH_SECRET are missing, too short, are known placeholder values, or are identical to each other - Wire assertJwtSecretsSecure() call into src/index.ts before server bind - Add unit tests: src/utils/__tests__/jwtSecurity.test.ts (17 cases) - env.ts already enforces secrets via Zod schema; this layer adds human-readable log output Closes Gildado#439 Closes Gildado#438 Closes Gildado#457
|
@leojay-net Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
…der and BulkPaymentTracker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #439 | Closes #438 | Closes #457
#439 – Standardize API Error Response Format
Problem: API errors were inconsistent across the codebase — various shapes like
{ error },{ error, details },{ message }.Solution:
backend/src/utils/apiError.tswithapiErrorResponse(code, message, details)helper andErrorCodesconstants{ code: string, message: string, details: unknown[] }app.tsmiddlewares/auth.tsJWT authentication errorsauthController.ts(register, login, 2FA setup/verify/disable, refresh)employeeController.ts(create, getAll, getOne, update, delete)codeandmessagefieldsbackend/src/utils/__tests__/apiError.test.ts#438 – Detailed Deployment Guide for Vercel/Render
Problem: No step-by-step cloud deployment documentation existed.
Solution:
DEPLOYMENT_GUIDE_CLOUD.mdat the repository root covering:#457 – Secure JWT Keys with Environment Variables
Problem: If JWT secrets were left as placeholders, the server started silently with insecure tokens.
Solution:
backend/src/utils/jwtSecurity.tswith:validateJwtSecret()— rejects missing, short, or placeholder valuesvalidateSecretsAreDistinct()— rejects reuse of the same secret for both tokensassertJwtSecretsSecure()— logs actionable errors and callsprocess.exit(1)if insecureassertJwtSecretsSecure(process.env)intosrc/index.ts— server aborts before bindingbackend/src/utils/__tests__/jwtSecurity.test.tsTest Results
Pre-existing failures in the repo (e.g.
env.test.tsSTELLAR_NETWORK_PASSPHRASE,logger.test.ts) are unrelated to this PR and existed onmainbefore these changes.