UNPKG

1.94 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 return new (P || (P = Promise))(function (resolve, reject) {
5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 step((generator = generator.apply(thisArg, _arguments || [])).next());
9 });
10};
11Object.defineProperty(exports, "__esModule", { value: true });
12const passport = require("passport");
13function PassportStrategy(Strategy, name) {
14 class MixinStrategy extends Strategy {
15 constructor(...args) {
16 const callback = (...params) => __awaiter(this, void 0, void 0, function* () {
17 const done = params[params.length - 1];
18 try {
19 const validateResult = yield this.validate(...params);
20 if (Array.isArray(validateResult)) {
21 done(null, ...validateResult);
22 }
23 else {
24 done(null, validateResult);
25 }
26 }
27 catch (err) {
28 done(err, null);
29 }
30 });
31 super(...args, callback);
32 const passportInstance = this.getPassportInstance();
33 if (name) {
34 passportInstance.use(name, this);
35 }
36 else {
37 passportInstance.use(this);
38 }
39 }
40 getPassportInstance() {
41 return passport;
42 }
43 }
44 return MixinStrategy;
45}
46exports.PassportStrategy = PassportStrategy;