Skip to content

Commit fa68aa6

Browse files
Merge branch 'TBG-FR-fix-createPassportContext-error'
2 parents 7a60892 + 5dbaa7c commit fa68aa6

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/auth.guard.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,22 @@ export type IAuthGuard = CanActivate & {
2121
logIn<TRequest extends { logIn: Function } = any>(
2222
request: TRequest
2323
): Promise<void>;
24-
handleRequest<TUser = any>(err, user, info, context: ExecutionContext, status?): TUser;
25-
getAuthenticateOptions(context: ExecutionContext): IAuthModuleOptions | undefined;
24+
handleRequest<TUser = any>(
25+
err,
26+
user,
27+
info,
28+
context: ExecutionContext,
29+
status?
30+
): TUser;
31+
getAuthenticateOptions(
32+
context: ExecutionContext
33+
): IAuthModuleOptions | undefined;
2634
};
2735
export const AuthGuard: (type?: string | string[]) => Type<IAuthGuard> =
2836
memoize(createAuthGuard);
2937

3038
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.`;
39+
const authLogger = new Logger('AuthGuard');
3140

3241
function createAuthGuard(type?: string | string[]): Type<CanActivate> {
3342
class MixinAuthGuard<TUser = any> implements CanActivate {
@@ -38,7 +47,7 @@ function createAuthGuard(type?: string | string[]): Type<CanActivate> {
3847
constructor(@Optional() options?: AuthModuleOptions) {
3948
this.options = options ?? this.options;
4049
if (!type && !this.options.defaultStrategy) {
41-
new Logger('AuthGuard').error(NO_STRATEGY_ERROR);
50+
authLogger.error(NO_STRATEGY_ERROR);
4251
}
4352
}
4453

@@ -82,6 +91,7 @@ function createAuthGuard(type?: string | string[]): Type<CanActivate> {
8291

8392
handleRequest(err, user, info, context, status): TUser {
8493
if (err || !user) {
94+
authLogger.error(info);
8595
throw err || new UnauthorizedException();
8696
}
8797
return user;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"dist",
2121
"index.js",
2222
"index.d.ts"
23-
]
23+
],
2424
"peerDependencies": {
2525
"@nestjs/common": "^8.0.0 || ^9.0.0",
2626
"passport": "^0.4.0 || ^0.5.0 || ^0.6.0"

0 commit comments

Comments
 (0)