From 871bf00764bcc30b69de4fd860d6f2b43174af89 Mon Sep 17 00:00:00 2001 From: Julien Ferrier Date: Wed, 10 Feb 2021 15:47:31 +0100 Subject: [PATCH 1/5] feat: add getRequest method int IAuthGuard interface --- lib/auth.guard.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/auth.guard.ts b/lib/auth.guard.ts index d6547798..fbf44b5a 100644 --- a/lib/auth.guard.ts +++ b/lib/auth.guard.ts @@ -22,6 +22,7 @@ export type IAuthGuard = CanActivate & { ): Promise; handleRequest(err, user, info, context, status?): TUser; getAuthenticateOptions(context): IAuthModuleOptions | undefined; + getRequest(context: ExecutionContext): T; }; export const AuthGuard: ( type?: string | string[] @@ -29,7 +30,7 @@ export const AuthGuard: ( const NO_STRATEGY_ERROR = `In order to use "defaultStrategy", please, ensure to import PassportModule in each place where AuthGuard() is being used. Otherwise, passport won't work correctly.`; -function createAuthGuard(type?: string | string[]): Type { +function createAuthGuard(type?: string | string[]): Type { class MixinAuthGuard implements CanActivate { constructor(@Optional() protected readonly options?: AuthModuleOptions) { this.options = this.options || {}; From 4408774fc41feef4b74397ef99eed8e9e6963a7d Mon Sep 17 00:00:00 2001 From: Jonathan Lang Date: Mon, 20 Feb 2023 14:46:01 +0100 Subject: [PATCH 2/5] feat: Allow specifying callback arity --- lib/passport/passport.strategy.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/passport/passport.strategy.ts b/lib/passport/passport.strategy.ts index b614f769..745b4151 100644 --- a/lib/passport/passport.strategy.ts +++ b/lib/passport/passport.strategy.ts @@ -3,7 +3,8 @@ import { Type } from '../interfaces'; export function PassportStrategy = any>( Strategy: T, - name?: string | undefined + name?: string | undefined, + callbackArity?: true | Number ): { new (...args): InstanceType; } { @@ -24,17 +25,17 @@ export function PassportStrategy = any>( done(err, null); } }; - /** - * Commented out due to the regression it introduced - * Read more here: https://github.com/nestjs/passport/issues/446 + if (callbackArity !== undefined) { const validate = new.target?.prototype?.validate; + const arity = + callbackArity === true ? validate.length + 1 : callbackArity; if (validate) { Object.defineProperty(callback, 'length', { - value: validate.length + 1 + value: arity }); } - */ + } super(...args, callback); const passportInstance = this.getPassportInstance(); From e8bf13177f3e99e66a1954f7c2bcd9c9048749ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Tue, 13 Jun 2023 09:34:12 +0200 Subject: [PATCH 3/5] chore: laying the grounds for v10.0.0 --- .circleci/config.yml | 13 ++++++------- package.json | 2 +- tsconfig.build.json | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 324b9d73..d21874dd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,15 +3,15 @@ version: 2 aliases: - &restore-cache restore_cache: - key: dependency-cache-{{ checksum "package.json" }} + key: dependency-cache-{{ checksum "package.json" }} - &install-deps run: - name: Install dependencies - command: npm ci + name: Install dependencies + command: npm ci --ignore-scripts - &build-packages run: - name: Build - command: npm run build + name: Build + command: npm run build jobs: build: @@ -27,7 +27,7 @@ jobs: key: dependency-cache-{{ checksum "package.json" }} - run: name: Install dependencies - command: npm ci + command: npm ci --ignore-scripts - save_cache: key: dependency-cache-{{ checksum "package.json" }} paths: @@ -44,4 +44,3 @@ workflows: build-and-test: jobs: - build - diff --git a/package.json b/package.json index 8eec0ed4..460f41bd 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "index.d.ts" ], "peerDependencies": { - "@nestjs/common": "^8.0.0 || ^9.0.0", + "@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0", "passport": "^0.4.0 || ^0.5.0 || ^0.6.0" }, "devDependencies": { diff --git a/tsconfig.build.json b/tsconfig.build.json index 2cb7090c..e4906abd 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -7,7 +7,7 @@ "noLib": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, - "target": "es6", + "target": "ES2021", "sourceMap": false, "outDir": "./dist", "rootDir": "./lib", From 57a96ead409ad0162c2b56316e07839fea381425 Mon Sep 17 00:00:00 2001 From: Kamil Mysliwiec Date: Tue, 13 Jun 2023 09:35:33 +0200 Subject: [PATCH 4/5] Update lib/passport/passport.strategy.ts --- lib/passport/passport.strategy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/passport/passport.strategy.ts b/lib/passport/passport.strategy.ts index 745b4151..f60e4d6f 100644 --- a/lib/passport/passport.strategy.ts +++ b/lib/passport/passport.strategy.ts @@ -4,7 +4,7 @@ import { Type } from '../interfaces'; export function PassportStrategy = any>( Strategy: T, name?: string | undefined, - callbackArity?: true | Number + callbackArity?: true | number ): { new (...args): InstanceType; } { From e0e566142c464a7065ed9d3c8a8afc07f799e14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Tue, 13 Jun 2023 09:40:59 +0200 Subject: [PATCH 5/5] fix: add explicit type assertion --- lib/auth.guard.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/auth.guard.ts b/lib/auth.guard.ts index d29d177b..69b3b4a2 100644 --- a/lib/auth.guard.ts +++ b/lib/auth.guard.ts @@ -105,7 +105,7 @@ function createAuthGuard(type?: string | string[]): Type { } } const guard = mixin(MixinAuthGuard); - return guard; + return guard as Type; } const createPassportContext =