Skip to content

Commit

Permalink
refactor(env-provider): 🎉 add new env providers
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhangunduz committed Aug 22, 2023
1 parent 8597462 commit 886305a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/api/keycloak.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import Keycloak from "keycloak-js";
import {
envKeycloakAuthURL,
envKeycloakClientID,
envKeycloakRealm,
} from "../helpers/envProvider";

const keycloak = new Keycloak({
url: process.env.REACT_APP_KEYCLOAK_URL!,
realm: process.env.REACT_APP_KEYCLOAK_REALM!,
clientId: process.env.REACT_APP_KEYCLOAK_CLIENT_ID!,
url: envKeycloakAuthURL,
realm: envKeycloakRealm,
clientId: envKeycloakClientID,
});

export default keycloak;
3 changes: 2 additions & 1 deletion src/contexts/GithubContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getGithubAccessTokenwithRefreshToken,
} from "../toolkit/GithubSlice";
import { useNavigate } from "react-router-dom";
import { envKeycloakClientID } from "../helpers/envProvider";
export const GithubContext: any = createContext<any>(null);

// eslint-disable-next-line
Expand Down Expand Up @@ -53,7 +54,7 @@ export default ({ children }: any) => {
}, [githubToken]);

function getGithubAppCode() {
window.location.href = `https://github.com/login/oauth/authorize?client_id=${process.env.REACT_APP_GITHUB_APP_CLIENT_ID}&state=${window.location.pathname}`;
window.location.href = `https://github.com/login/oauth/authorize?client_id=${envKeycloakClientID}&state=${window.location.pathname}`;
}

function getGithubAppToken() {
Expand Down
9 changes: 9 additions & 0 deletions src/helpers/envProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ export const envFrontendUrl: string = process.env.REACT_APP_FRONTEND_URL || "";

export const isProduction: boolean =
process.env.NODE_ENV === "production" ? true : false;

export const envKeycloakAuthURL: string =
process.env.REACT_APP_KEYCLOAK_URL || "";

export const envKeycloakRealm: string =
process.env.REACT_APP_KEYCLOAK_REALM || "";

export const envKeycloakClientID: string =
process.env.REACT_APP_KEYCLOAK_CLIENT_ID || "";

0 comments on commit 886305a

Please sign in to comment.