From 21af5402425cbd559449b32f683a688af3851499 Mon Sep 17 00:00:00 2001 From: annarhughes Date: Mon, 24 Jun 2024 17:57:37 +0100 Subject: [PATCH] ignore id token expired --- src/firebase/firebase-auth.guard.ts | 3 ++- src/partner-admin/partner-admin-auth.guard.ts | 3 ++- src/partner-admin/super-admin-auth.guard.ts | 3 ++- src/utils/errors.ts | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/firebase/firebase-auth.guard.ts b/src/firebase/firebase-auth.guard.ts index 27f7881e..2c7d66a0 100644 --- a/src/firebase/firebase-auth.guard.ts +++ b/src/firebase/firebase-auth.guard.ts @@ -7,6 +7,7 @@ import { UnauthorizedException, } from '@nestjs/common'; import { Request } from 'express'; +import { FIREBASE_ERRORS } from 'src/utils/errors'; import { AuthService } from '../auth/auth.service'; import { UserService } from '../user/user.service'; import { IFirebaseUser } from './firebase-user.interface'; @@ -32,7 +33,7 @@ export class FirebaseAuthGuard implements CanActivate { user = await this.authService.parseAuth(authorization); } catch (error) { if (error.code === 'auth/id-token-expired') { - throw new HttpException(`FirebaseAuthGuard - ${error}`, HttpStatus.UNAUTHORIZED); + throw new HttpException(FIREBASE_ERRORS.ID_TOKEN_EXPIRED, HttpStatus.UNAUTHORIZED); } throw new HttpException( diff --git a/src/partner-admin/partner-admin-auth.guard.ts b/src/partner-admin/partner-admin-auth.guard.ts index 6c664993..c36e6420 100644 --- a/src/partner-admin/partner-admin-auth.guard.ts +++ b/src/partner-admin/partner-admin-auth.guard.ts @@ -8,6 +8,7 @@ import { import { InjectRepository } from '@nestjs/typeorm'; import { Request } from 'express'; import { UserEntity } from 'src/entities/user.entity'; +import { FIREBASE_ERRORS } from 'src/utils/errors'; import { Repository } from 'typeorm'; import { AuthService } from '../auth/auth.service'; @@ -31,7 +32,7 @@ export class PartnerAdminAuthGuard implements CanActivate { userUid = uid; } catch (error) { if (error.code === 'auth/id-token-expired') { - throw new HttpException(`PartnerAdminAuthGuard - ${error}`, HttpStatus.UNAUTHORIZED); + throw new HttpException(FIREBASE_ERRORS.ID_TOKEN_EXPIRED, HttpStatus.UNAUTHORIZED); } throw new HttpException( diff --git a/src/partner-admin/super-admin-auth.guard.ts b/src/partner-admin/super-admin-auth.guard.ts index da1c6a7d..4f4de5d4 100644 --- a/src/partner-admin/super-admin-auth.guard.ts +++ b/src/partner-admin/super-admin-auth.guard.ts @@ -8,6 +8,7 @@ import { import { InjectRepository } from '@nestjs/typeorm'; import { Request } from 'express'; import { UserEntity } from 'src/entities/user.entity'; +import { FIREBASE_ERRORS } from 'src/utils/errors'; import { Repository } from 'typeorm'; import { AuthService } from '../auth/auth.service'; @@ -35,7 +36,7 @@ export class SuperAdminAuthGuard implements CanActivate { userUid = uid; } catch (error) { if (error.code === 'auth/id-token-expired') { - throw new HttpException(`SuperAdminAuthGuard - ${error}`, HttpStatus.UNAUTHORIZED); + throw new HttpException(FIREBASE_ERRORS.ID_TOKEN_EXPIRED, HttpStatus.UNAUTHORIZED); } throw new HttpException( diff --git a/src/utils/errors.ts b/src/utils/errors.ts index 0d9a7457..9d793985 100644 --- a/src/utils/errors.ts +++ b/src/utils/errors.ts @@ -6,4 +6,5 @@ export enum FIREBASE_ERRORS { CREATE_USER_INVALID_EMAIL = 'CREATE_USER_INVALID_EMAIL', CREATE_USER_WEAK_PASSWORD = 'CREATE_USER_WEAK_PASSWORD', CREATE_USER_ALREADY_EXISTS = 'CREATE_USER_ALREADY_EXISTS', + ID_TOKEN_EXPIRED = 'ID_TOKEN_EXPIRED', }