0.0.1 โข Published 5 months ago
@gotocva/nestjs-auth v0.0.1
๐ @gotocva/nestjs-auth
A NestJS Auth Library built with Mongoose and Passport, providing ready-to-use authentication features:
- Register
- Login
- Email verification (via OTP)
- Reset Password
๐ฆ Installation
npm install @gotocva/nestjs-auth
Or if using Yarn:
yarn add @gotocva/nestjs-auth
Ensure
@nestjs/mongoose
,mongoose
,bcrypt
, andclass-validator
are installed in your host app.
โ๏ธ Setup in Your NestJS App
1. Import AuthModule
// app.module.ts or auth.module.ts
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { AuthModule } from '@gotocva/nestjs-auth';
@Module({
imports: [
MongooseModule.forRoot('mongodb://localhost/your-db'),
AuthModule,
],
})
export class AppModule {}
๐ Endpoints
Method | Path | Description |
---|---|---|
POST | /auth/register | Register a user |
POST | /auth/login | Login user |
POST | /auth/verify-email | Verify OTP from email |
POST | /auth/reset-password | Reset user password |
๐งช Example Payloads
๐ธ Register
POST /auth/register
{
"name": "John Doe",
"email": "john@example.com",
"password": "Password123"
}
๐ธ Login
POST /auth/login
{
"email": "john@example.com",
"password": "Password123"
}
๐ธ Verify Email
POST /auth/verify-email
{
"email": "john@example.com",
"otp": "123456"
}
๐ธ Reset Password
POST /auth/reset-password
{
"email": "john@example.com",
"otp": "123456",
"newPassword": "NewPassword123"
}
๐ ๏ธ Customize
- Extend the
UserSchema
to add more fields (e.g., role, profileImage) - Hook up an email service (e.g., nodemailer, SendGrid) to send OTPs
- Add JWT if you need token-based auth (this library only covers login + verification)
๐ License
MIT ยฉ Sivabharathy
0.0.1
5 months ago