Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
chore: created and added new errors in jwt.strategy.ts file
Balu Babud3a43cb65f72
diff --git a/packages/hoppscotch-backend/src/auth/strategies/jwt.strategy.ts b/packages/hoppscotch-backend/src/auth/strategies/jwt.strategy.tsindex f3aea0d27..735027cd0 100644--- a/packages/hoppscotch-backend/src/auth/strategies/jwt.strategy.ts+++ b/packages/hoppscotch-backend/src/auth/strategies/jwt.strategy.ts@@ -10,6 +10,11 @@ import { UserService } from 'src/user/user.service';import { AuthService } from '../auth.service';import { Request } from 'express';import * as O from 'fp-ts/Option';+import {+ COOKIES_NOT_FOUND,+ INVALID_ACCESS_TOKEN,+ USER_NOT_FOUND,+} from 'src/errors';@Injectable()export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {@@ -22,7 +27,7 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {(request: Request) => {const ATCookie = request.cookies['access_token'];if (!ATCookie) {- throw new ForbiddenException('No cookies present');+ throw new ForbiddenException(COOKIES_NOT_FOUND);}return ATCookie;},@@ -32,12 +37,12 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {}async validate(payload: AccessTokenPayload) {- if (!payload) throw new ForbiddenException('Access token malformed');+ if (!payload) throw new ForbiddenException(INVALID_ACCESS_TOKEN);const user = await this.usersService.findUserById(payload.sub);if (O.isNone(user)) {- throw new UnauthorizedException('User not found');+ throw new UnauthorizedException(USER_NOT_FOUND);}const profile = {diff --git a/packages/hoppscotch-backend/src/errors.ts b/packages/hoppscotch-backend/src/errors.tsindex b967a0f48..ce44db307 100644--- a/packages/hoppscotch-backend/src/errors.ts+++ b/packages/hoppscotch-backend/src/errors.ts@@ -234,3 +234,15 @@ export const TOKEN_EXPIRED = 'auth/token_expired' as const;* (AuthService)*/export const MAGIC_LINK_EXPIRED = 'auth/magic_link_expired' as const;++/**+ * No cookies were found in the auth request+ * (AuthService)+ */+export const COOKIES_NOT_FOUND = 'auth/cookies_not_found' as const;++/**+ * Access Token is malformed or invalid+ * (AuthService)+ */+export const INVALID_ACCESS_TOKEN = 'auth/invalid_access_token' as const;