Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix errors related to auth #180

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading