Skip to content

Commit

Permalink
debug: env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Shurtu-gal committed Sep 19, 2023
1 parent c98fca5 commit 84128cb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
40 changes: 26 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,36 @@ jobs:
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{steps.dev-cache.outputs.cache-hit != 'true'}}
name: Install Dependencies
run: yarn install
# - if: ${{steps.dev-cache.outputs.cache-hit != 'true'}}
# name: Install Dependencies
# run: yarn install

- name: Create production ENV
env:
GATSBY_FIREBASE_API_KEY: ${{ vars.GATSBY_FIREBASE_API_KEY }}
GATSBY_FIREBASE_AUTH_DOMAIN: ${{ vars.GATSBY_FIREBASE_AUTH_DOMAIN }}
GATSBY_FIREBASE_PROJECT_ID: ${{ vars.GATSBY_FIREBASE_PROJECT_ID }}
GATSBY_FIREBASE_STORAGE_BUCKET: ${{ vars.GATSBY_FIREBASE_STORAGE_BUCKET }}
GATSBY_FIREBASE_MESSAGING_SENDER_ID: ${{ vars.GATSBY_FIREBASE_MESSAGING_SENDER_ID }}
GATSBY_FIREBASE_APP_ID: ${{ vars.GATSBY_FIREBASE_APP_ID }}
GATSBY_FIREBASE_MEASUREMENT_ID: ${{ vars.GATSBY_FIREBASE_MEASUREMENT_ID }}
GATSBY_API_URL: ${{ vars.GATSBY_API_URL }}

run: |
touch .env.production
echo "GATSBY_FIREBASE_API_KEY=${{ vars.GATSBY_FIREBASE_API_KEY }}" >> .env.production
echo "GATSBY_FIREBASE_AUTH_DOMAIN=${{ vars.GATSBY_FIREBASE_AUTH_DOMAIN }}" >> .env.production
echo "GATSBY_FIREBASE_PROJECT_ID=${{ vars.GATSBY_FIREBASE_PROJECT_ID }}" >> .env.production
echo "GATSBY_FIREBASE_STORAGE_BUCKET=${{ vars.GATSBY_FIREBASE_STORAGE_BUCKET }}" >> .env.production
echo "GATSBY_FIREBASE_MESSAGING_SENDER_ID=${{ vars.GATSBY_FIREBASE_MESSAGING_SENDER_ID }}" >> .env.production
echo "GATSBY_FIREBASE_APP_ID=${{ vars.GATSBY_FIREBASE_APP_ID }}" >> .env.production
echo "GATSBY_FIREBASE_MEASUREMENT_ID=${{ vars.GATSBY_FIREBASE_MEASUREMENT_ID }}" >> .env.production
echo "GATSBY_API_URL=${{ vars.GATSBY_API_URL }}" >> .env.production
echo "${{ vars.GATSBY_API_URL }}"
echo "GATSBY_FIREBASE_API_KEY=${GATSBY_FIREBASE_API_KEY}"
echo "GATSBY_FIREBASE_AUTH_DOMAIN=$GATSBY_FIREBASE_AUTH_DOMAIN"
echo "GATSBY_FIREBASE_PROJECT_ID=$GATSBY_FIREBASE_PROJECT_ID"
echo "GATSBY_FIREBASE_STORAGE_BUCKET=$GATSBY_FIREBASE_STORAGE_BUCKET"
echo "GATSBY_FIREBASE_MESSAGING_SENDER_ID=$GATSBY_FIREBASE_MESSAGING_SENDER_ID"
echo "GATSBY_FIREBASE_APP_ID=$GATSBY_FIREBASE_APP_ID"
echo "GATSBY_FIREBASE_MEASUREMENT_ID=$GATSBY_FIREBASE_MEASUREMENT_ID"
echo "GATSBY_API_URL=$GATSBY_API_URL"
echo "repository variable : ${{ vars.REPOSITORY_VARIABLE }}"
cat .env.production
- name: Build Check
run: yarn build
continue-on-error: ${{ !inputs.fail-on-error }}
# - name: Build Check
# run: yarn build
# continue-on-error: ${{ !inputs.fail-on-error }}

6 changes: 4 additions & 2 deletions src/config/firebase.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';

export const firebaseConfig = {
apiKey: process.env.GATSBY_FIREBASE_API_KEY,
Expand All @@ -10,5 +11,6 @@ export const firebaseConfig = {
measurementId: process.env.GATSBY_FIREBASE_MEASUREMENT_ID,
};

// Initialize Firebase
export const app = initializeApp(firebaseConfig);
// Initialize Firebase or a dummy app if no config is provided
export const app = initializeApp(process.env.GATSBY_FIREBASE_API_KEY ? firebaseConfig : {});
export const auth = getAuth(app);
11 changes: 4 additions & 7 deletions src/utils/Auth.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// eslint-disable-next-line react-hooks/exhaustive-deps
/* eslint-disable no-console */
import React, { createContext, useEffect, useMemo, useState } from 'react';
import { GoogleAuthProvider, getAuth, signInWithPopup, onAuthStateChanged } from 'firebase/auth';
import { GoogleAuthProvider, signInWithPopup, onAuthStateChanged } from 'firebase/auth';
import { Redirect } from '@reach/router';
import { navigate } from 'gatsby';
import { app } from '../config/firebase';
import { auth } from '../config/firebase';
import { avenueApi } from './api';

const provider = new GoogleAuthProvider();
Expand All @@ -26,9 +26,6 @@ const AuthContextProvider = ({ children }) => {
const [userData, setUserData] = useState({});
const [token, setToken] = useState('');

// initializing auth
const auth = getAuth(app);

// Setting user id on changing auth state
useEffect(() => {
onAuthStateChanged(auth, (users) => {
Expand Down Expand Up @@ -59,7 +56,7 @@ const AuthContextProvider = ({ children }) => {
<Redirect to='/' />;
}
});
}, [auth]);
}, []);

const value = useMemo(() => {
// login method
Expand Down Expand Up @@ -105,7 +102,7 @@ const AuthContextProvider = ({ children }) => {
logout,
setUserData,
};
}, [auth, authenticated, token, userData]);
}, [authenticated, token, userData]);

return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
};
Expand Down

0 comments on commit 84128cb

Please sign in to comment.