Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

feat: prefix VITE_ added in conditional auth provider env variable (#3246) (HBE-248)

Mir Arif Hasan2c1fd5d711a3
diff --git a/.env.example b/.env.example
index fe0d68c00..56a4e0016 100644
--- a/.env.example
+++ b/.env.example
@@ -13,7 +13,7 @@ SESSION_SECRET='add some secret here'
# Hoppscotch App Domain Config
REDIRECT_URL="http://localhost:3000"
WHITELISTED_ORIGINS = "http://localhost:3170,http://localhost:3000,http://localhost:3100"
-ALLOWED_AUTH_PROVIDERS = GOOGLE,GITHUB,MICROSOFT,EMAIL
+VITE_ALLOWED_AUTH_PROVIDERS = GOOGLE,GITHUB,MICROSOFT,EMAIL
# Google Auth Config
GOOGLE_CLIENT_ID="************************************************"
diff --git a/packages/hoppscotch-backend/src/auth/helper.ts b/packages/hoppscotch-backend/src/auth/helper.ts
index 3c87a045e..e5e485700 100644
--- a/packages/hoppscotch-backend/src/auth/helper.ts
+++ b/packages/hoppscotch-backend/src/auth/helper.ts
@@ -107,7 +107,7 @@ export const subscriptionContextCookieParser = (rawCookies: string) => {
};
/**
- * Check to see if given auth provider is present in the ALLOWED_AUTH_PROVIDERS env variable
+ * Check to see if given auth provider is present in the VITE_ALLOWED_AUTH_PROVIDERS env variable
*
* @param provider Provider we want to check the presence of
* @returns Boolean if provider specified is present or not
@@ -117,8 +117,8 @@ export function authProviderCheck(provider: string) {
throwErr(AUTH_PROVIDER_NOT_SPECIFIED);
}
- const envVariables = process.env.ALLOWED_AUTH_PROVIDERS
- ? process.env.ALLOWED_AUTH_PROVIDERS.split(',').map((provider) =>
+ const envVariables = process.env.VITE_ALLOWED_AUTH_PROVIDERS
+ ? process.env.VITE_ALLOWED_AUTH_PROVIDERS.split(',').map((provider) =>
provider.trim().toUpperCase(),
)
: [];
diff --git a/packages/hoppscotch-backend/src/errors.ts b/packages/hoppscotch-backend/src/errors.ts
index 451aab645..6fb4a4a13 100644
--- a/packages/hoppscotch-backend/src/errors.ts
+++ b/packages/hoppscotch-backend/src/errors.ts
@@ -29,22 +29,22 @@ export const JSON_INVALID = 'json_invalid';
export const AUTH_PROVIDER_NOT_SPECIFIED = 'auth/provider_not_specified';
/**
- * Environment variable "ALLOWED_AUTH_PROVIDERS" is not present in .env file
+ * Environment variable "VITE_ALLOWED_AUTH_PROVIDERS" is not present in .env file
*/
export const ENV_NOT_FOUND_KEY_AUTH_PROVIDERS =
- '"ALLOWED_AUTH_PROVIDERS" is not present in .env file';
+ '"VITE_ALLOWED_AUTH_PROVIDERS" is not present in .env file';
/**
- * Environment variable "ALLOWED_AUTH_PROVIDERS" is empty in .env file
+ * Environment variable "VITE_ALLOWED_AUTH_PROVIDERS" is empty in .env file
*/
export const ENV_EMPTY_AUTH_PROVIDERS =
- '"ALLOWED_AUTH_PROVIDERS" is empty in .env file';
+ '"VITE_ALLOWED_AUTH_PROVIDERS" is empty in .env file';
/**
- * Environment variable "ALLOWED_AUTH_PROVIDERS" contains unsupported provider in .env file
+ * Environment variable "VITE_ALLOWED_AUTH_PROVIDERS" contains unsupported provider in .env file
*/
export const ENV_NOT_SUPPORT_AUTH_PROVIDERS =
- '"ALLOWED_AUTH_PROVIDERS" contains an unsupported auth provider in .env file';
+ '"VITE_ALLOWED_AUTH_PROVIDERS" contains an unsupported auth provider in .env file';
/**
* Tried to delete a user data document from fb firestore but failed.
diff --git a/packages/hoppscotch-backend/src/utils.ts b/packages/hoppscotch-backend/src/utils.ts
index c095683d1..d9817c1c0 100644
--- a/packages/hoppscotch-backend/src/utils.ts
+++ b/packages/hoppscotch-backend/src/utils.ts
@@ -9,7 +9,12 @@ import * as E from 'fp-ts/Either';
import * as A from 'fp-ts/Array';
import { TeamMemberRole } from './team/team.model';
import { User } from './user/user.model';
-import { ENV_EMPTY_AUTH_PROVIDERS, ENV_NOT_FOUND_KEY_AUTH_PROVIDERS, ENV_NOT_SUPPORT_AUTH_PROVIDERS, JSON_INVALID } from './errors';
+import {
+ ENV_EMPTY_AUTH_PROVIDERS,
+ ENV_NOT_FOUND_KEY_AUTH_PROVIDERS,
+ ENV_NOT_SUPPORT_AUTH_PROVIDERS,
+ JSON_INVALID,
+} from './errors';
import { AuthProvider } from './auth/helper';
/**
@@ -156,21 +161,21 @@ export function isValidLength(title: string, length: number) {
/**
* This function is called by bootstrap() in main.ts
- * It checks if the "ALLOWED_AUTH_PROVIDERS" environment variable is properly set or not.
+ * It checks if the "VITE_ALLOWED_AUTH_PROVIDERS" environment variable is properly set or not.
* If not, it throws an error.
*/
export function checkEnvironmentAuthProvider() {
- if (!process.env.hasOwnProperty('ALLOWED_AUTH_PROVIDERS')) {
+ if (!process.env.hasOwnProperty('VITE_ALLOWED_AUTH_PROVIDERS')) {
throw new Error(ENV_NOT_FOUND_KEY_AUTH_PROVIDERS);
}
- if (process.env.ALLOWED_AUTH_PROVIDERS === '') {
+ if (process.env.VITE_ALLOWED_AUTH_PROVIDERS === '') {
throw new Error(ENV_EMPTY_AUTH_PROVIDERS);
}
- const givenAuthProviders = process.env.ALLOWED_AUTH_PROVIDERS.split(',').map(
- (provider) => provider.toLocaleUpperCase(),
- );
+ const givenAuthProviders = process.env.VITE_ALLOWED_AUTH_PROVIDERS.split(
+ ',',
+ ).map((provider) => provider.toLocaleUpperCase());
const supportedAuthProviders = Object.values(AuthProvider).map(
(provider: string) => provider.toLocaleUpperCase(),
);