diff --git a/mirror-web-server/src/auth/auth.guard.ts b/mirror-web-server/src/auth/auth.guard.ts index ec8c0c85..c05f1e98 100644 --- a/mirror-web-server/src/auth/auth.guard.ts +++ b/mirror-web-server/src/auth/auth.guard.ts @@ -42,7 +42,10 @@ export class AuthGuardFirebase implements CanActivate { req['user'] = decodedJwt } } catch (error) { - console.log(error) + this.logger.log( + `JWT decode error ${error as string}`, + AuthGuardFirebase.name + ) // do nothing if decoding fails here } return true @@ -88,14 +91,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({