UNPKG

@wristband/nestjs-auth

Version:

SDK for integrating your NestJS application with Wristband. Handles user authentication and token management.

90 lines (89 loc) 4.31 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 WristbandExpressAuthModule_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.WristbandExpressAuthModule = void 0; const common_1 = require("@nestjs/common"); const express_auth_service_1 = require("./express-auth.service"); /** * The WristbandExpressAuthModule is a dynamic NestJS module that integrates the Wristband Authentication Service * for NestJS/Express-based applications. It allows for the configuration and injection of the * `WristbandExpressAuthService`, enabling authentication functionality within the application. * * It offers a flexible setup through its `forRoot` method, allowing configuration of the service with custom * `AuthConfig` as well as custom names for service injection, ensuring flexibility when multiple instances are * required. * * Usage: * - Call `forRoot` with the desired `AuthConfig` and an optional token name to set up the module. * - The module exports the `WristbandExpressAuthService` and any custom token provided, making it available across the app. * * Example: * * ```typescript * WristbandExpressAuthModule.forRoot({ clientId: 'your-client-id', clientSecret: 'your-client-secret' }); * ``` * * This module is designed to be globally available, ensuring the `WristbandExpressAuthService` can be easily injected * and used across different modules in the application. */ let WristbandExpressAuthModule = WristbandExpressAuthModule_1 = class WristbandExpressAuthModule { /** * Configures and initializes the WristbandExpressAuthModule with the provided authentication configuration. * * Example: * * ```typescript * WristbandExpressAuthModule.forRoot({ * clientId: 'your-client-id', * clientSecret: 'your-client-secret', * ... * }, 'myWristbandAuth'); * ``` * * @param {AuthConfig} config - The configuration object for the Wristband SDK, containing authentication details * such as `clientId`, `clientSecret`, and other relevant settings. * @param {string} [token='wristband'] - Optional token name used to identify the service in the module's context. * Defaults to `'wristband'` if not provided, enabling support for multiple instances of the service. * @returns {DynamicModule} - A NestJS DynamicModule that provides and exports the `WristbandExpressAuthService` * and the custom token. */ static forRoot(config, token = 'wristband') { return { module: WristbandExpressAuthModule_1, global: true, providers: [ { provide: 'AUTH_CONFIG', useValue: config, }, { provide: token, useClass: express_auth_service_1.WristbandExpressAuthService, }, { provide: express_auth_service_1.WristbandExpressAuthService, useFactory: (authConfig) => { return new express_auth_service_1.WristbandExpressAuthService(authConfig); }, inject: ['AUTH_CONFIG'], }, ], exports: [express_auth_service_1.WristbandExpressAuthService, token], }; } }; exports.WristbandExpressAuthModule = WristbandExpressAuthModule; exports.WristbandExpressAuthModule = WristbandExpressAuthModule = WristbandExpressAuthModule_1 = __decorate([ (0, common_1.Module)({ imports: [], controllers: [], providers: [express_auth_service_1.WristbandExpressAuthService], exports: [express_auth_service_1.WristbandExpressAuthService], }) ], WristbandExpressAuthModule);