From 689ead2d1aeec3cece1e05ed8df73c31efc8d4ec Mon Sep 17 00:00:00 2001 From: Rybasher Date: Thu, 16 May 2024 13:39:50 +0300 Subject: [PATCH] fix: fix errors related to auth --- mirror-web-server/src/auth/auth.guard.ts | 6 +++--- mirror-web-server/src/user/user.service.ts | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mirror-web-server/src/auth/auth.guard.ts b/mirror-web-server/src/auth/auth.guard.ts index ec8c0c85..a7ec218d 100644 --- a/mirror-web-server/src/auth/auth.guard.ts +++ b/mirror-web-server/src/auth/auth.guard.ts @@ -42,7 +42,7 @@ export class AuthGuardFirebase implements CanActivate { req['user'] = decodedJwt } } catch (error) { - console.log(error) + this.logger.log(`JWT decode error ${error}`, AuthGuardFirebase.name) // do nothing if decoding fails here } return true @@ -88,14 +88,14 @@ export class AuthGuardFirebase implements CanActivate { } else { this.logger.error('JWT:', token) } - console.log('AuthGuardFirebase: error decoding jwt, returning false') + this.logger.log('AuthGuardFirebase: error decoding jwt, returning false') return false } } async decodeJwt(token) { return await this.firebaseAuthService.verifyIdToken( - token.replace('Bearer ', ''), + token ? token.replace('Bearer ', '') : '', true ) } diff --git a/mirror-web-server/src/user/user.service.ts b/mirror-web-server/src/user/user.service.ts index 000fcde9..f3dd3b5c 100644 --- a/mirror-web-server/src/user/user.service.ts +++ b/mirror-web-server/src/user/user.service.ts @@ -191,18 +191,18 @@ export class UserService { } async ensureMirrorUserExists(token: string) { - const decodedToken = await this.firebaseAuthService.verifyIdToken(token) - const firebaseUID = decodedToken.uid + try { + const decodedToken = await this.firebaseAuthService.verifyIdToken(token) + const firebaseUID = decodedToken.uid - const _id = new mongo.ObjectId() + const _id = new mongo.ObjectId() - if (!decodedToken) { - throw new NotFoundException('User not found') - } + if (!decodedToken) { + throw new NotFoundException('User not found') + } - const user = await this.userModel.findOne({ firebaseUID }).exec() + const user = await this.userModel.findOne({ firebaseUID }).exec() - try { if (!user) { const displayName = this._generateUniqueUsername() const userModel = new this.userModel({