UNPKG

@next-nest-auth/nestauth

Version:

NestAuth is an authentication solution for NestJS applications, designed to handle user login, session management, and token-based authentication (JWT). It integrates seamlessly with Next.js and other frontends to provide a unified authentication system,

126 lines 5.92 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.createDynamicController = createDynamicController; const common_1 = require("@nestjs/common"); const nestauth_service_1 = require("./nestauth.service"); const nestauth_google_guard_1 = require("./nestauth-google.guard"); const nestauth_facebook_guard_1 = require("./nestauth-facebook.guard"); const http_exception_filter_1 = require("./http-exception.filter"); function createDynamicController(prefix, nestAuthServiceToken, localGuard) { let NestAuthController = class NestAuthController { constructor(nestAuthService) { this.nestAuthService = nestAuthService; } async greetings() { return "Welcome to NestAuth. Please check our documentation for more information."; } async login(req) { return this.nestAuthService.login(req.user); } refreshToken(params) { if (!params.refresh_token) { throw new common_1.BadRequestException("Invalid or expired refresh token"); } return this.nestAuthService.refreshToken(params.refresh_token); } async googleAuth(req) { } googleAuthRedirect(req) { if (!req.user) { throw new common_1.UnauthorizedException("Unable to login with Google"); } return this.nestAuthService.google(req.user); } async facebookLogin() { return common_1.HttpStatus.OK; } async facebookLoginRedirect(req) { if (!req.user) { throw new common_1.UnauthorizedException("Unable to login with Facebook"); } return this.nestAuthService.facebook(req.user); } async logout(req) { return req.logout(); } }; __decorate([ (0, common_1.All)(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], NestAuthController.prototype, "greetings", null); __decorate([ (0, common_1.UseGuards)(localGuard), (0, common_1.Post)("login"), __param(0, (0, common_1.Request)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], NestAuthController.prototype, "login", null); __decorate([ (0, common_1.Post)("refresh-token"), __param(0, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], NestAuthController.prototype, "refreshToken", null); __decorate([ (0, common_1.UseGuards)(nestauth_google_guard_1.NestAuthGoogleGuard), (0, common_1.Get)("google"), __param(0, (0, common_1.Request)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], NestAuthController.prototype, "googleAuth", null); __decorate([ (0, common_1.Get)("google-redirect"), (0, common_1.UseGuards)(nestauth_google_guard_1.NestAuthGoogleGuard), __param(0, (0, common_1.Request)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], NestAuthController.prototype, "googleAuthRedirect", null); __decorate([ (0, common_1.Get)("/facebook"), (0, common_1.UseGuards)(nestauth_facebook_guard_1.NestAuthFacebookGuard), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], NestAuthController.prototype, "facebookLogin", null); __decorate([ (0, common_1.Get)("/facebook-redirect"), (0, common_1.UseGuards)(nestauth_facebook_guard_1.NestAuthFacebookGuard), __param(0, (0, common_1.Request)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], NestAuthController.prototype, "facebookLoginRedirect", null); __decorate([ (0, common_1.UseGuards)(localGuard), (0, common_1.Get)("logout"), __param(0, (0, common_1.Request)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], NestAuthController.prototype, "logout", null); NestAuthController = __decorate([ (0, common_1.UseFilters)(http_exception_filter_1.HttpExceptionFilter), (0, common_1.Controller)(prefix), __param(0, (0, common_1.Inject)(nestAuthServiceToken)), __metadata("design:paramtypes", [nestauth_service_1.NestAuthService]) ], NestAuthController); return NestAuthController; } //# sourceMappingURL=nestauth.controller.js.map