0

I am setting up CICD with Github actions and Firebase hosting.

I have two different workflows, one to deploy after a PR and one after a merge.

Both deploy well.

However, after the merge has deployed, I get a blank page and this error:

index-690a584b.js:827 Uncaught FirebaseError: Firebase: Error (auth/invalid-api-key).
    at createErrorInternal (index-690a584b.js:827:504)
    at _assert (index-690a584b.js:827:559)
    at index-690a584b.js:1892:391
    at Component.instanceFactory (index-690a584b.js:1892:791)
    at Provider.getOrInitializeService (index-690a584b.js:617:2996)
    at Provider.initialize (index-690a584b.js:617:2312)
    at initializeAuth (index-690a584b.js:857:209)
    at getAuth (index-690a584b.js:1907:612)
    at index-690a584b.js:3362:11767

This is my github action yaml:

name: Deploy to Firebase Hosting on merge
'on':
  push:
    branches:
      - main
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3   
      - uses: actions/setup-node@v3 
        with:   
          node-version: '18'
      - run: |
          cd front
          echo "$ENV_DEVELOPMENT" > .env.development
          PWD=$(pwd)
          npm install
          sh -ac ". $PWD/.env.development; npm run build"
        env:
          ENV_DEVELOPMENT: ${{ secrets.ENV_DEVELOPMENT }}
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          entrypoint: ./front
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_MYCOMPANY_DEV }}'
          channelId: live
          projectId: mycompany-dev

The only differences to the working action are the name, the on conditions when it runs, and the channelId: live.

I have added the ENV_DEVELOPMENT variable to Github secrets and it includes all my Firebase variables.

How could I get rid of the error?

ppt
  • 946
  • 8
  • 18
  • Is this resolved? Setting `PWD` is redundant. See https://stackoverflow.com/a/55191543/7670262. Why are you invoking another shell `sh` to source vars and run `npm run build` command? Does `ENV_DEVELOPMENT` env var contain the Firebase creds? Which step is that error coming from? Did you verify your Firebase service account? – Azeem Mar 11 '23 at 10:09
  • Not resolved. Yes, ENV_DEVELOPMENT contains Firebase creds. The error occurs in the browser after I visit the deployed site. I'm not sure what you mean by verifying my Firebase service account. – ppt Mar 13 '23 at 17:32
  • According to that error "**FirebaseError: Firebase: Error (auth/invalid-api-key)**", your API key is invalid. I was referring to whether you tested it locally and verified that it was working. If yes, you need to replicate the same in your workflow as well. – Azeem Mar 14 '23 at 04:05

0 Answers0