Skip to content

Commit

Permalink
fix: fix errors related to auth (#180)
Browse files Browse the repository at this point in the history
* fix: fix errors related to auth

* fix: fix lint error
  • Loading branch information
Rybasher authored May 16, 2024
1 parent 7166535 commit 8d99fd6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
9 changes: 6 additions & 3 deletions mirror-web-server/src/auth/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
}
Expand Down
16 changes: 8 additions & 8 deletions mirror-web-server/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 8d99fd6

Please sign in to comment.