0.0.1 โ€ข Published 5 months ago

@gotocva/nestjs-auth v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

๐Ÿ” @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, and class-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

MethodPathDescription
POST/auth/registerRegister a user
POST/auth/loginLogin user
POST/auth/verify-emailVerify OTP from email
POST/auth/reset-passwordReset 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