UNPKG

nestjs-auth-kit

Version:

A modular and flexible authentication kit for NestJS with JWT, social login, OTP, and password reset.

127 lines 5.29 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthController = void 0; const common_1 = require("@nestjs/common"); const auth_service_1 = require("./auth.service"); const jwt_auth_guard_1 = require("./guards/jwt-auth.guard"); const roles_guard_1 = require("./guards/roles.guard"); const roles_decorator_1 = require("./decorators/roles.decorator"); const register_dto_1 = require("./dto/register.dto"); let AuthController = class AuthController { constructor(authService) { this.authService = authService; } async register(registerDto) { return this.authService.register(registerDto); } async login(loginDto) { return this.authService.login(loginDto); } async googleLogin(req) { return this.authService.validateGoogleUser(req.user); } async facebookLogin(req) { return this.authService.validateFacebookUser(req.user); } async sendOtp(email) { return this.authService.sendOtp(email); } async verifyOtp(email, otp) { return this.authService.verifyOtp(email, otp); } async resetPassword(email, otp, newPassword) { return this.authService.resetPassword(email, otp, newPassword); } async getProfile(req) { return req.user; } getAdminData() { return { message: 'Admin data' }; } }; exports.AuthController = AuthController; __decorate([ (0, common_1.Post)('register'), __param(0, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [register_dto_1.RegisterDto]), __metadata("design:returntype", Promise) ], AuthController.prototype, "register", null); __decorate([ (0, common_1.Post)('login'), __param(0, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AuthController.prototype, "login", null); __decorate([ (0, common_1.Get)('google'), __param(0, (0, common_1.Req)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AuthController.prototype, "googleLogin", null); __decorate([ (0, common_1.Get)('facebook'), __param(0, (0, common_1.Req)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AuthController.prototype, "facebookLogin", null); __decorate([ (0, common_1.Post)('otp'), __param(0, (0, common_1.Body)('email')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], AuthController.prototype, "sendOtp", null); __decorate([ (0, common_1.Post)('otp/verify'), __param(0, (0, common_1.Body)('email')), __param(1, (0, common_1.Body)('otp')), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String]), __metadata("design:returntype", Promise) ], AuthController.prototype, "verifyOtp", null); __decorate([ (0, common_1.Post)('password-reset'), __param(0, (0, common_1.Body)('email')), __param(1, (0, common_1.Body)('otp')), __param(2, (0, common_1.Body)('newPassword')), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, String]), __metadata("design:returntype", Promise) ], AuthController.prototype, "resetPassword", null); __decorate([ (0, common_1.Get)('me'), (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard), __param(0, (0, common_1.Req)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AuthController.prototype, "getProfile", null); __decorate([ (0, common_1.Get)('admin'), (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, roles_guard_1.RolesGuard), (0, roles_decorator_1.Roles)('admin'), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], AuthController.prototype, "getAdminData", null); exports.AuthController = AuthController = __decorate([ (0, common_1.Controller)('auth'), __metadata("design:paramtypes", [auth_service_1.AuthService]) ], AuthController); //# sourceMappingURL=auth.controller.js.map