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,

96 lines 4.66 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 NestAuthModule_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.NestAuthModule = void 0; const common_1 = require("@nestjs/common"); const config_1 = require("@nestjs/config"); const nestauth_service_1 = require("./nestauth.service"); const nestauth_controller_1 = require("./nestauth.controller"); const passport_1 = require("@nestjs/passport"); const jwt_1 = require("@nestjs/jwt"); const nestauth_jwt_strategy_1 = require("./nestauth-jwt.strategy"); const nestauth_google_strategy_1 = require("./nestauth-google.strategy"); const nestauth_facebook_strategy_1 = require("./nestauth-facebook.strategy"); const nestauth_local_strategy_1 = require("./nestauth-local.strategy"); const nestauth_local_guard_1 = require("./nestauth-local.guard"); let NestAuthModule = NestAuthModule_1 = class NestAuthModule { static forRoot(options) { const JwtSecretProvider = { provide: "JWT_SECRET", useValue: options.jwtSecret || "60s", }; const JwtExpiresInProvider = { provide: "JWT_EXPIRES_IN", useValue: options.jwtExpiresIn, }; const JwtRefreshTokenExpiresInProvider = { provide: "JWT_REFRESH_TOKEN_EXPIRES_IN", useValue: options.jwtRefreshTokenExpiresIn, }; const controllerPath = options.routePrefix ? `${options.routePrefix.replace(/^\/|\/$/g, "")}/nestauth` : "nestauth"; const pathKey = controllerPath.replaceAll("/", "_").toUpperCase(); const userServiceToken = `NEST_AUTH_USER_SERVICE_${pathKey}`; const nestAuthServiceToken = `NEST_AUTH_SERVICE_${pathKey}`; const strategyName = `${pathKey}-local`; const LocalStrategy = (0, nestauth_local_strategy_1.createLocalStrategy)(strategyName, userServiceToken); const LocalGuard = (0, nestauth_local_guard_1.createLocalGuard)(strategyName); const controller = (0, nestauth_controller_1.createDynamicController)(controllerPath, nestAuthServiceToken, LocalGuard); return { module: NestAuthModule_1, imports: [ jwt_1.JwtModule.registerAsync({ imports: [], inject: [], useFactory: async () => ({ secret: options.jwtSecret, signOptions: { expiresIn: options.jwtExpiresIn, }, }), }), (0, common_1.forwardRef)(() => options.UserModule), ], providers: [ { provide: userServiceToken, useExisting: options.UserService, }, { provide: nestAuthServiceToken, useFactory: (jwtService, userService, jwtExpiresIn, jwtRefreshTokenExpiresIn) => new nestauth_service_1.NestAuthService(jwtService, userService, jwtExpiresIn, jwtRefreshTokenExpiresIn), inject: [ jwt_1.JwtService, userServiceToken, "JWT_EXPIRES_IN", "JWT_REFRESH_TOKEN_EXPIRES_IN", ], }, nestauth_jwt_strategy_1.NestAuthJwtStrategy, nestauth_google_strategy_1.NestAuthGoogleStrategy, nestauth_facebook_strategy_1.NestAuthFacebookStrategy, JwtSecretProvider, JwtExpiresInProvider, JwtRefreshTokenExpiresInProvider, LocalStrategy, LocalGuard, ], exports: [nestAuthServiceToken], controllers: [controller], }; } }; exports.NestAuthModule = NestAuthModule; exports.NestAuthModule = NestAuthModule = NestAuthModule_1 = __decorate([ (0, common_1.Module)({ imports: [passport_1.PassportModule, config_1.ConfigModule.forRoot({})], }) ], NestAuthModule); //# sourceMappingURL=nestauth.module.js.map