A robust Node.js/TypeScript authentication system providing:
- Secure OTP generation/validation
- JWT-based authentication
- Password reset flows
- Prisma-based database integration
- Redis caching for OTP/session management
Available on NPM!
You can install this package using either npm or pnpm:
npm install @thischirag/auth
pnpm add @thischirag/auth
For more information, refer to the NPM Package Documentation or NPM-Package.md.
- Overview
- Features
- Requirements
- Environment Configuration
- Local Development
- Docker Deployment
- Email Services
- Scripts & Commands
- Testing via Swagger
- Contributing
- License
- Contact
Chirag Auth Validator is an all-in-one, developer-friendly solution for OTP-based email validation and JWT-based authentication. It uses PostgreSQL for persistent storage, Redis for caching, and integrates with Prisma for schema-based ORM functionality. The project also includes a Swagger UI hosted at auth.chiragcodes.com for easy API testing and documentation.
- OTP Generation & Validation
- JWT Authentication
- Password Reset
- Prisma Integration
- Redis Support
- Flexible Email Providers
- Node.js (v16+ recommended)
- pnpm (for package management)
- PostgreSQL (local or via Docker)
- Redis (local or via Docker)
- Docker & Docker Compose (for containerized deployment)
- Copy
.env.example
to.env
:cp .env.example .env
- Set the Environment Mode:
- For development:
NODE_ENV="development"
- For production:
NODE_ENV="production"
- For development:
- Fill in the required fields:
DATABASE_URL
: Connection string for PostgreSQL.REDIS_URL
: Connection string for Redis.JWT_SECRET
: Secret key for JWT tokens.RESEND_API_KEY
: API key for Resend email service.- Note: Ensure your domain is verified before using the Resend API key.
YOUR_DOMAIN
: Use the format[email protected]
to ensure proper email delivery.
- Keep
.env
private:- Ensure
.env
is listed in.gitignore
to avoid committing sensitive data.
- Ensure
- Install Dependencies:
pnpm install
- Prisma Migrations & Generation:
npx prisma migrate dev npx prisma generate
- Run Development Server:
This starts the app on
pnpm run dev
PORT=8080
(by default) or whatever port you set in.env
.
-
PostgreSQL (Local or Docker):
docker run --name pg-container \ -e POSTGRES_PASSWORD=mysecretpassword \ -p 5432:5432 \ -d postgres
Or install locally and update
.env
:DATABASE_URL="postgresql://postgres:mysecretpassword@localhost:5432/postgres?schema=public"
-
Redis (Local or Docker):
docker run --name redis-container \ -p 6379:6379 \ -d redis
Or install locally and update
.env
:REDIS_URL="redis://localhost:6379"
Docker Compose simplifies running multiple containers (PostgreSQL, Redis, and your application) together.
-
Ensure Your
.env
File is ConfiguredUpdate
.env
to reference the service names defined indocker-compose.yml
:DATABASE_URL="postgresql://postgres:mysecretpassword@postgres:5432/postgres?schema=public" REDIS_URL="redis://redis:6379"
-
Make the Entrypoint Script Executable Ensure the
docker-entrypoint.sh
file is executable:chmod +x docker-entrypoint.sh
-
Run the Containers
docker-compose up --build -d
-
Apply Prisma Migrations
docker-compose exec app pnpm prisma migrate deploy docker-compose exec app pnpm prisma generate
-
Verify the Setup
- Check Logs (Optional):
docker-compose logs -f app
- Stop the Containers:
docker-compose down
- Check Logs (Optional):
- Resend:
- Set
RESEND_API_KEY
in.env
. - Ensure your domain is verified before using the Resend API key.
- Use the format
[email protected]
forYOUR_DOMAIN
in.env
to ensure proper email delivery.
- Set
Command | Description |
---|---|
pnpm install |
Install dependencies |
pnpm run dev |
Start dev server on specified PORT |
pnpm run build |
Compile TypeScript into dist/ |
pnpm run lint |
Run ESLint checks |
pnpm run lint:fix |
Autofix lint errors where possible |
pnpm run format |
Format code with Prettier |
pnpm prisma migrate deploy |
Apply DB migrations in production |
pnpm prisma generate |
Re-generate Prisma client |
docker build -t <image> . |
Build Docker image from Dockerfile |
docker-compose up --build -d |
Build & start all services (Postgres, Redis, app) in detached mode |
docker-compose exec app <cmd> |
Execute <cmd> inside the app container |
docker-compose logs -f app |
Follow the logs of the app container |
docker-compose down |
Stop & remove all containers, networks, and volumes |
-
Hosted Swagger
- Test all API endpoints on auth.chiragcodes.com.
-
Local Swagger
- Update the
servers:
section inopenapi.yml
to:servers: - url: http://localhost:8080/api description: Local Development Server
- Then navigate to http://localhost:8080/docs to test endpoints.
- Update the
-
Fork the Repo
-
Create a Branch
git checkout -b feature/new-feature
-
Make Changes & Test
-
Commit & Push
git commit -m "Add new feature" git push origin feature/new-feature
-
Open a Pull Request on GitHub
This project is licensed under the MIT License.
- Website: chiragcodes.com
- Email: [email protected]
- Alternate: [email protected]
For issues or suggestions, feel free to open a GitHub issue or reach out via email.