diff --git a/src/modules/auth/auth.service.ts b/src/modules/auth/auth.service.ts index 9753d40..88f68a1 100644 --- a/src/modules/auth/auth.service.ts +++ b/src/modules/auth/auth.service.ts @@ -1,11 +1,11 @@ import { Injectable, UnauthorizedException } from "@nestjs/common"; import { ConfigService } from "@nestjs/config"; import * as jwt from "jsonwebtoken"; -import JwksRsa, * as jwksRsa from "jwks-rsa"; +import * as jwksRsa from "jwks-rsa"; @Injectable() export class AuthService { - private jwksClient: JwksRsa.JwksClient; + private jwksClient: jwksRsa.JwksClient; constructor(configService: ConfigService) { this.jwksClient = jwksRsa({ diff --git a/src/modules/auth/guards/jwt.guard.ts b/src/modules/auth/guards/jwt.guard.ts index 2d3444a..5a17fc3 100644 --- a/src/modules/auth/guards/jwt.guard.ts +++ b/src/modules/auth/guards/jwt.guard.ts @@ -14,7 +14,7 @@ export class JwtAuthGuard implements CanActivate { private readonly userService: UserService, private readonly authService: AuthService, private readonly configService: ConfigService, - ) {} + ) { } async canActivate(context: ExecutionContext): Promise { const request = context.switchToHttp().getRequest(); @@ -30,7 +30,9 @@ export class JwtAuthGuard implements CanActivate { let user = await this.userService.findOrCreate({ id: jwtPayload.sub.toString(), username: - jwtPayload[this.configService.get("auth.usernameField")], + jwtPayload[this.configService.get("auth.usernameField")] || + jwtPayload["preferred_username"] || + jwtPayload["email"], }); request.user = user;