Skip to content

Commit

Permalink
style: rename to authLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Feb 1, 2023
1 parent 50eb1bb commit 5dbaa7c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions lib/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,22 @@ export type IAuthGuard = CanActivate & {
logIn<TRequest extends { logIn: Function } = any>(
request: TRequest
): Promise<void>;
handleRequest<TUser = any>(err, user, info, context: ExecutionContext, status?): TUser;
getAuthenticateOptions(context: ExecutionContext): IAuthModuleOptions | undefined;
handleRequest<TUser = any>(
err,
user,
info,
context: ExecutionContext,
status?
): TUser;
getAuthenticateOptions(
context: ExecutionContext
): IAuthModuleOptions | undefined;
};
export const AuthGuard: (type?: string | string[]) => Type<IAuthGuard> =
memoize(createAuthGuard);

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

function createAuthGuard(type?: string | string[]): Type<CanActivate> {
class MixinAuthGuard<TUser = any> implements CanActivate {
Expand All @@ -39,7 +47,7 @@ function createAuthGuard(type?: string | string[]): Type<CanActivate> {
constructor(@Optional() options?: AuthModuleOptions) {
this.options = options ?? this.options;
if (!type && !this.options.defaultStrategy) {
AUTH_LOGGER.error(NO_STRATEGY_ERROR);
authLogger.error(NO_STRATEGY_ERROR);
}
}

Expand Down Expand Up @@ -83,7 +91,7 @@ function createAuthGuard(type?: string | string[]): Type<CanActivate> {

handleRequest(err, user, info, context, status): TUser {
if (err || !user) {
AUTH_LOGGER.error(info);
authLogger.error(info);
throw err || new UnauthorizedException();
}
return user;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dist",
"index.js",
"index.d.ts"
]
],
"peerDependencies": {
"@nestjs/common": "^8.0.0 || ^9.0.0",
"passport": "^0.4.0 || ^0.5.0 || ^0.6.0"
Expand Down

0 comments on commit 5dbaa7c

Please sign in to comment.