Skip to content

Commit 8d99fd6

Browse files
authored
fix: fix errors related to auth (#180)
* fix: fix errors related to auth * fix: fix lint error
1 parent 7166535 commit 8d99fd6

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

mirror-web-server/src/auth/auth.guard.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export class AuthGuardFirebase implements CanActivate {
4242
req['user'] = decodedJwt
4343
}
4444
} catch (error) {
45-
console.log(error)
45+
this.logger.log(
46+
`JWT decode error ${error as string}`,
47+
AuthGuardFirebase.name
48+
)
4649
// do nothing if decoding fails here
4750
}
4851
return true
@@ -88,14 +91,14 @@ export class AuthGuardFirebase implements CanActivate {
8891
} else {
8992
this.logger.error('JWT:', token)
9093
}
91-
console.log('AuthGuardFirebase: error decoding jwt, returning false')
94+
this.logger.log('AuthGuardFirebase: error decoding jwt, returning false')
9295
return false
9396
}
9497
}
9598

9699
async decodeJwt(token) {
97100
return await this.firebaseAuthService.verifyIdToken(
98-
token.replace('Bearer ', ''),
101+
token ? token.replace('Bearer ', '') : '',
99102
true
100103
)
101104
}

mirror-web-server/src/user/user.service.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,18 @@ export class UserService {
191191
}
192192

193193
async ensureMirrorUserExists(token: string) {
194-
const decodedToken = await this.firebaseAuthService.verifyIdToken(token)
195-
const firebaseUID = decodedToken.uid
194+
try {
195+
const decodedToken = await this.firebaseAuthService.verifyIdToken(token)
196+
const firebaseUID = decodedToken.uid
196197

197-
const _id = new mongo.ObjectId()
198+
const _id = new mongo.ObjectId()
198199

199-
if (!decodedToken) {
200-
throw new NotFoundException('User not found')
201-
}
200+
if (!decodedToken) {
201+
throw new NotFoundException('User not found')
202+
}
202203

203-
const user = await this.userModel.findOne({ firebaseUID }).exec()
204+
const user = await this.userModel.findOne({ firebaseUID }).exec()
204205

205-
try {
206206
if (!user) {
207207
const displayName = this._generateUniqueUsername()
208208
const userModel = new this.userModel({

0 commit comments

Comments
 (0)