diff --git a/package.json b/package.json index 789148d4f..3d3aab201 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "staart-manager", - "version": "1.1.28", + "version": "1.1.29", "main": "index.js", "repository": "git@github.com:AnandChowdhary/staart.git", "author": "Anand Chowdhary ", @@ -144,5 +144,5 @@ "setup" ], "snyk": true, - "staart-version": "1.1.28" + "staart-version": "1.1.29" } \ No newline at end of file diff --git a/src/helpers/jwt.ts b/src/helpers/jwt.ts index 39fcab5b0..9254063d0 100644 --- a/src/helpers/jwt.ts +++ b/src/helpers/jwt.ts @@ -7,8 +7,7 @@ import { TOKEN_EXPIRY_LOGIN, TOKEN_EXPIRY_REFRESH, TOKEN_EXPIRY_APPROVE_LOCATION, - TOKEN_EXPIRY_API_KEY_MAX, - REDIS_URL + TOKEN_EXPIRY_API_KEY_MAX } from "../config"; import { User, AccessToken } from "../interfaces/tables/user"; import { Tokens, ErrorCode, EventType, Templates } from "../interfaces/enum"; @@ -33,8 +32,8 @@ import { getGeolocationFromIp } from "./location"; import i18n from "../i18n"; import { ApiKey } from "../interfaces/tables/organization"; import cryptoRandomString from "crypto-random-string"; -import { createHandyClient } from "handy-redis"; import ipRangeCheck from "ip-range-check"; +import { redis } from "./redis"; /** * Generate a new JWT @@ -239,21 +238,18 @@ export const getLoginResponse = async ( return await postLoginTokens(user, locals); }; -const client = createHandyClient({ - url: REDIS_URL -}); - /** * Check if a token is invalidated in Redis * @param token - JWT */ export const checkInvalidatedToken = async (token: string) => { + if (!redis) return; const details = decode(token); if ( details && typeof details === "object" && details.jti && - (await client.get(`${JWT_ISSUER}-revoke-${details.sub}-${details.jti}`)) + (await redis.get(`${JWT_ISSUER}-revoke-${details.sub}-${details.jti}`)) ) throw new Error(ErrorCode.REVOKED_TOKEN); }; @@ -263,9 +259,10 @@ export const checkInvalidatedToken = async (token: string) => { * @param token - JWT */ export const invalidateToken = async (token: string) => { + if (!redis) return; const details = decode(token); if (details && typeof details === "object" && details.jti) - client.set( + redis.set( `${JWT_ISSUER}-revoke-${details.sub}-${details.jti}`, "1", details.exp && [ diff --git a/src/helpers/redis.ts b/src/helpers/redis.ts new file mode 100644 index 000000000..160d63949 --- /dev/null +++ b/src/helpers/redis.ts @@ -0,0 +1,6 @@ +import { createHandyClient } from "handy-redis"; +import { REDIS_URL } from "../config"; + +export const redis = createHandyClient({ + url: REDIS_URL +}); diff --git a/src/interfaces/enum.ts b/src/interfaces/enum.ts index 51d4b3b98..58ef534fe 100644 --- a/src/interfaces/enum.ts +++ b/src/interfaces/enum.ts @@ -88,7 +88,8 @@ export enum ErrorCode { DOMAIN_MISSING_FILE = "400/domain-missing-file", DOMAIN_MISSING_DNS = "400/domain-missing-dns", DOMAIN_ALREADY_VERIFIED = "400/domain-already-verified", - CANNOT_INVITE_DOMAIN = "400/cannot-invite-domain" + CANNOT_INVITE_DOMAIN = "400/cannot-invite-domain", + UNABLE_TO_SEND_EMAIL = "500/unable-to-email" } export enum Templates {