Skip to content

Commit

Permalink
Refactor code to improve performance and readability
Browse files Browse the repository at this point in the history
  • Loading branch information
zepor committed Dec 20, 2023
1 parent 842c10e commit 2102fe0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/be.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ jobs:
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
- name: Build and push image to ACR
env:
VITE_COGNITO_USER_POOL_ID: ${{ secrets.VITE_COGNITO_USER_POOL_ID }}
VITE_COGNITO_CLIENT_ID: ${{ secrets.VITE_COGNITO_CLIENT_ID }}
run: |
export VITE_COGNITO_USER_POOL_ID=${{ secrets.VITE_COGNITO_USER_POOL_ID }}
export VITE_COGNITO_CLIENT_ID=${{ secrets.VITE_COGNITO_CLIENT_ID }}
az acr build --image be:${{ github.sha }} --registry ${{ secrets.AZURE_CONTAINER_REGISTRY }} -g ${{ secrets.ACR_RESOURCE_GROUP }} -f backend-container/Dockerfile.python backend-container/
az acr build --image be:latest --registry ${{ secrets.AZURE_CONTAINER_REGISTRY }} -g ${{ secrets.ACR_RESOURCE_GROUP }} -f backend-container/Dockerfile.python backend-container/
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/fe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ jobs:
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
- name: Build and push image to ACR
env:
VITE_COGNITO_USER_POOL_ID: ${{ secrets.VITE_COGNITO_USER_POOL_ID }}
VITE_COGNITO_CLIENT_ID: ${{ secrets.VITE_COGNITO_CLIENT_ID }}
run: |
export VITE_COGNITO_USER_POOL_ID=${{ secrets.VITE_COGNITO_USER_POOL_ID }}
export VITE_COGNITO_CLIENT_ID=${{ secrets.VITE_COGNITO_CLIENT_ID }}
az acr build --image fe:${{ github.sha }} --registry ${{ secrets.AZURE_CONTAINER_REGISTRY }} -g ${{ secrets.ACR_RESOURCE_GROUP }} -f frontend-container/Dockerfile.Prod frontend-container/
az acr build --image fe:latest --registry ${{ secrets.AZURE_CONTAINER_REGISTRY }} -g ${{ secrets.ACR_RESOURCE_GROUP }} -f frontend-container/Dockerfile.Prod frontend-container/
deploy:
Expand Down
18 changes: 15 additions & 3 deletions frontend-container/src/contexts/CognitoProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@ import {
CognitoUserPool,
} from "amazon-cognito-identity-js";
import axios from "../utils/axios";
import { cognitoConfig } from "../config";
import { cognitoConfig as devCognitoConfig } from "../config";
import AuthContext from "./CognitoContext";

const INITIALIZE = "INITIALIZE";
const SIGN_OUT = "SIGN_OUT";

// Function to get Cognito configuration
const getCognitoConfig = () => {
const userPoolId =
process.env.VITE_COGNITO_USER_POOL_ID || devCognitoConfig.userPoolId;
const clientId =
process.env.VITE_COGNITO_CLIENT_ID || devCognitoConfig.clientId;

return { userPoolId, clientId };
};

const { userPoolId, clientId } = getCognitoConfig();

const UserPool = new CognitoUserPool({
UserPoolId: cognitoConfig.userPoolId || "",
ClientId: cognitoConfig.clientId || "",
UserPoolId: userPoolId || "",
ClientId: clientId || "",
});

const initialState = {
Expand Down

0 comments on commit 2102fe0

Please sign in to comment.