HSB-482 fix: add env missing checks (#4282)
fix: add env missing checks
This commit is contained in:
@@ -49,6 +49,12 @@ export const AUTH_PROVIDER_NOT_CONFIGURED =
|
|||||||
export const ENV_NOT_FOUND_KEY_AUTH_PROVIDERS =
|
export const ENV_NOT_FOUND_KEY_AUTH_PROVIDERS =
|
||||||
'"VITE_ALLOWED_AUTH_PROVIDERS" is not present in .env file';
|
'"VITE_ALLOWED_AUTH_PROVIDERS" is not present in .env file';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Environment variable "DATA_ENCRYPTION_KEY" is not present in .env file
|
||||||
|
*/
|
||||||
|
export const ENV_NOT_FOUND_KEY_DATA_ENCRYPTION_KEY =
|
||||||
|
'"DATA_ENCRYPTION_KEY" is not present in .env file';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Environment variable "VITE_ALLOWED_AUTH_PROVIDERS" is empty in .env file
|
* Environment variable "VITE_ALLOWED_AUTH_PROVIDERS" is empty in .env file
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { AuthProvider } from './auth/helper';
|
|||||||
import {
|
import {
|
||||||
ENV_EMPTY_AUTH_PROVIDERS,
|
ENV_EMPTY_AUTH_PROVIDERS,
|
||||||
ENV_NOT_FOUND_KEY_AUTH_PROVIDERS,
|
ENV_NOT_FOUND_KEY_AUTH_PROVIDERS,
|
||||||
|
ENV_NOT_FOUND_KEY_DATA_ENCRYPTION_KEY,
|
||||||
ENV_NOT_SUPPORT_AUTH_PROVIDERS,
|
ENV_NOT_SUPPORT_AUTH_PROVIDERS,
|
||||||
JSON_INVALID,
|
JSON_INVALID,
|
||||||
} from './errors';
|
} from './errors';
|
||||||
@@ -328,6 +329,8 @@ const ENCRYPTION_ALGORITHM = 'aes-256-cbc';
|
|||||||
* @returns The encrypted text
|
* @returns The encrypted text
|
||||||
*/
|
*/
|
||||||
export function encrypt(text: string, key = process.env.DATA_ENCRYPTION_KEY) {
|
export function encrypt(text: string, key = process.env.DATA_ENCRYPTION_KEY) {
|
||||||
|
if (!key) throw new Error(ENV_NOT_FOUND_KEY_DATA_ENCRYPTION_KEY);
|
||||||
|
|
||||||
if (text === null || text === undefined) return text;
|
if (text === null || text === undefined) return text;
|
||||||
|
|
||||||
const iv = crypto.randomBytes(16);
|
const iv = crypto.randomBytes(16);
|
||||||
@@ -351,6 +354,8 @@ export function decrypt(
|
|||||||
encryptedData: string,
|
encryptedData: string,
|
||||||
key = process.env.DATA_ENCRYPTION_KEY,
|
key = process.env.DATA_ENCRYPTION_KEY,
|
||||||
) {
|
) {
|
||||||
|
if (!key) throw new Error(ENV_NOT_FOUND_KEY_DATA_ENCRYPTION_KEY);
|
||||||
|
|
||||||
if (encryptedData === null || encryptedData === undefined) {
|
if (encryptedData === null || encryptedData === undefined) {
|
||||||
return encryptedData;
|
return encryptedData;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user