Skip to content

update firebase component to match firebase v9 update in redwoodjs#76

Open
doesnotexist wants to merge 16 commits intoredwoodjs:mainfrom
doesnotexist:firebase-v9
Open

update firebase component to match firebase v9 update in redwoodjs#76
doesnotexist wants to merge 16 commits intoredwoodjs:mainfrom
doesnotexist:firebase-v9

Conversation

@doesnotexist
Copy link
Copy Markdown
Contributor

Sibling pull-request in redwood here:
redwoodjs/graphql#3347

@netlify
Copy link
Copy Markdown

netlify bot commented Sep 10, 2021

‼️ Deploy request for redwood-playground-auth rejected.
Learn more about Netlify's sensitive variable policy

🔨 Explore the source changes: db1e2f7

import firebase from 'firebase/app'
import 'firebase/auth'
import { initializeApp, getApp, getApps } from 'firebase/app'
import * as firebaseAuth from '@firebase/auth'
Copy link
Copy Markdown
Contributor Author

@doesnotexist doesnotexist Sep 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately import * defeats the advantage of firebase v9 modular design to support tree-shaking, but the redwoodjs firebase authclient needs the app to 'inject' the firebase auth module like this, so that non-firebase auth apps do not require firebase as a dependency in their web/package.json

…User, fix imports that moved in newer version of redwood
Comment on lines +13 to +26
import admin from 'firebase-admin'

const config = {
apiKey: process.env.FIREBASE_API_KEY,
authDomain: process.env.FIREBASE_AUTH_DOMAIN,
databaseURL: process.env.FIREBASE_DATABASE_URL,
projectId: process.env.FIREBASE_PROJECT_ID,
storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.FIREBASE_APP_ID,
}

admin.initializeApp(config)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where to put the api-side firebase-admin initialization. Without this, the graphql endpoint currentUser handler will not work, because the token decoder uses firebase's verifyIdToken() to decode the JWT and verify it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By any chance @dthyresson or @dac09 have some input here?

I'm upgrading the playground auth from 0.36.0 to 0.37.0 and firebase seems broken. Maybe we could sort this PR out instead of a separate upgrade PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I upgraded the redwood dependencies in this PR to 0.37.0, had to add a api/src/directives as well and it seems to be working for me.

@doesnotexist
Copy link
Copy Markdown
Contributor Author

doesnotexist commented Oct 1, 2021

Upon upgrading to Redwood 0.37: everything seems to work for me but I do see this printed occasionally in the terminal which might indicate something is amiss:

api | ERROR [2021-10-01 16:05:12.687 +0000] (graphql-server): Error building context. Error: Exception in getAuthenticationContext: The `Authorization` header is not valid.
api | POST /graphql 200 13.408 ms - 44
api | ERROR [2021-10-01 16:05:35.473 +0000] (graphql-server): Error building context. Error: Exception in getAuthenticationContext: The `Authorization` header is not valid.

No longer seeing that, and I'm not exactly sure what changed if anything.


import admin from 'firebase-admin'

admin.initializeApp({ projectId: process.env.FIREBASE_PROJECT_ID })
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not sure where to put this firebase admin initialization, but I did pair down the config to only need PROJECT_ID.
A bit perplexed that no service account credentials were necessary since the documentation (https://firebase.google.com/docs/auth/admin/verify-id-tokens) for verifyIdToken states that you need to have a service account, but this works even without credentials from what I can tell.

@doesnotexist
Copy link
Copy Markdown
Contributor Author

Not sure this requireAuth() method in api/src/lib/auth is ever used or necessary, also is slightly confusing now that there is a requireAuth directive

export const requireAuth = () => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants