UNPKG

@denz93/vendure-plugin-3rd-party-auth

Version:

A set of auth strategies to work with 3rd party such as Google, Facebook, etc

76 lines (75 loc) 3.54 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 ThirdPartyAuthPlugin_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.ThirdPartyAuthPlugin = void 0; const axios_1 = require("@nestjs/axios"); const common_1 = require("@nestjs/common"); const core_1 = require("@vendure/core"); const constants_1 = require("./constants"); const cross_strategies_checker_service_1 = require("./cross-strategies-checker.service"); const facebook_auth_service_1 = require("./facebook-auth.service"); const facebook_auth_strategy_1 = require("./facebook-auth.strategy"); const google_auth_service_1 = require("./google-auth.service"); const google_auth_strategy_1 = require("./google-auth.strategy"); let ThirdPartyAuthPlugin = ThirdPartyAuthPlugin_1 = class ThirdPartyAuthPlugin { static init(options) { ThirdPartyAuthPlugin_1.options = { ...constants_1.DEFAULT_PLUGIN_OPTIONS, ...options }; return ThirdPartyAuthPlugin_1; } }; ThirdPartyAuthPlugin = ThirdPartyAuthPlugin_1 = __decorate([ (0, core_1.VendurePlugin)({ imports: [core_1.PluginCommonModule, axios_1.HttpModule], providers: [ { provide: constants_1.THIRD_PARTY_OPTIONS_PROVIDER, useFactory: () => { return ThirdPartyAuthPlugin_1.options; } }, { provide: google_auth_service_1.GoogleAuthService, inject: [constants_1.THIRD_PARTY_OPTIONS_PROVIDER], useFactory: async (options) => { if (!options.google) return null; return new google_auth_service_1.GoogleAuthService(options); } }, { provide: facebook_auth_service_1.FacebookAuthService, inject: [constants_1.THIRD_PARTY_OPTIONS_PROVIDER, common_1.HttpService], useFactory: async (options, httpService) => { if (!options.facebook) return null; return new facebook_auth_service_1.FacebookAuthService(httpService, options); } }, cross_strategies_checker_service_1.CrossStrategiesChecker ], configuration: (conf) => { const options = ThirdPartyAuthPlugin_1.options; for (let name of constants_1.LIST_OF_STRATEGY) { const optionDetail = options[name]; if (!optionDetail) { continue; } const strategy = name === 'google' ? new google_auth_strategy_1.GoogleAuthStrategy() : new facebook_auth_strategy_1.FacebookAuthStrategy(); conf.authOptions.shopAuthenticationStrategy.push(strategy); } return conf; } }) ], ThirdPartyAuthPlugin); exports.ThirdPartyAuthPlugin = ThirdPartyAuthPlugin;