Skip to content

Commit

Permalink
fix: env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
MOUAD EL AZAAR committed Feb 9, 2025
1 parent b69bf9c commit 4683f81
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
23 changes: 9 additions & 14 deletions src/envVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

type EnvVariableType = {
export type EnvVariableType = {
VITE_PEGASE_OAUTH2_CLIENT_ID: string;
VITE_PEGASE_OAUTH2_REDIRECT_URL: string;
VITE_PEGASE_OAUTH2_AUTHORITY: string;
VITE_BACK_END_BASE_URL: string;
VITE_OAUTH2_CLIENT_ID: string;
VITE_OAUTH2_REDIRECT_URL: string;
VITE_AUTHORITY: string;
};

// Environment Variable Template to Be Replaced at Runtime
export const envVariables: EnvVariableType = {
VITE_PEGASE_OAUTH2_CLIENT_ID: '${PEGASE_OAUTH2_CLIENT_ID}',
VITE_PEGASE_OAUTH2_REDIRECT_URL: '${PEGASE_OAUTH2_REDIRECT_URL}',
VITE_PEGASE_OAUTH2_AUTHORITY: '${PEGASE_OAUTH2_AUTHORITY}',
VITE_BACK_END_BASE_URL: '${URL_BACKEND}',
VITE_OAUTH2_CLIENT_ID: '${PEGASE_OAUTH2_CLIENT_ID}',
VITE_OAUTH2_REDIRECT_URL: '${PEGASE_OAUTH2_REDIRECT_URL}',
VITE_AUTHORITY: '${PEGASE_AUTHORITY}',
};
export const getEnvVariables = (key: keyof EnvVariableType): string => {
if (envVariables[key].startsWith('$')) {
return import.meta.env[key] as string;
} else {
return envVariables[key];
}
};
export const getEnvVariables = (key: keyof EnvVariableType) =>
envVariables[key].startsWith('$') ? (import.meta.env[key] as string) : envVariables[key];
4 changes: 1 addition & 3 deletions src/shared/const/apiEndPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

import { getEnvVariables } from '@/envVariables.ts';

const BASE_URL = getEnvVariables('VITE_BACK_END_BASE_URL');
const BASE_URL = import.meta.env.URL_BACKEND;

// STUDY
export const STUDY_ENDPOINT = `${BASE_URL}/v1/study`;
Expand Down
7 changes: 3 additions & 4 deletions src/shared/services/authService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { User, UserManager } from 'oidc-client-ts';
import { getEnvVariables } from '@/envVariables.ts';

interface AuthConfig {
authority: string;
Expand All @@ -16,9 +15,9 @@ interface AuthConfig {
}

const config: AuthConfig = {
client_id: getEnvVariables('VITE_OAUTH2_CLIENT_ID'),
redirect_uri: getEnvVariables('VITE_OAUTH2_REDIRECT_URL'),
authority: getEnvVariables('VITE_OAUTH2_REDIRECT_URL'),
client_id: import.meta.env.PEGASE_OAUTH2_CLIENT_ID,
redirect_uri: import.meta.env.PEGASE_OAUTH2_REDIRECT_URL,
authority: import.meta.env.PEGASE_OAUTH2_AUTHORITY,
scope: 'openid email profile',
maxExpiresIn: 600,
};
Expand Down

0 comments on commit 4683f81

Please sign in to comment.