Firebase Note
Switch to Firebase#
Hosting .firebaseapp.com
works but .web.app
fails#
- @2021-09-29
- Firebase default hosting domains: only
.firebaseapp.com
works but.web.app
fails - Same question on
SO
- Firebase/Contact Support
- My case: in \<12h it gets repaired.
Firebase documentation#
- @2021-09-29
- Was trying to set username in the sign up process, then I saw
user.updateProfile(profile)
, in V9 its actuallyAuth.updateProfile(User,Profile)
. - In the official doc, search result may be V8 but I'm using V9. Check your
@firebase
package version inpackage.json
and firebase CLI version withfirebase -V
. - [ ] TODO: Make the extension to show disable.
Handle Firebase App Error with React + Webpack#
- @2021-09-29
- Core:
getAuth()
will call a default APP defined byfirebase.initializeApp()
. - Error is rendered on yarn start page:
Error: Firebase: No Firebase App '[DEFAULT]' has been created.
- Caused by Webpack chunking(bootstrap). I did import the file with
initializeApp()
. What should be done is like this answer onSO
. But its only needed:- Modularize the
initializeApp
in one file(initFire
for me) and export anything(doesn't have to beapp
) - Import & Export before first usage of
getApp()
(methods likegetAuth()
will call it), - In this way, after Webpack it will still run first. (ES6
export {app} from "./initFire"
)
- Modularize the
Test realtime DB with jest#
- @2021-10-03
- Use RD for
realtime DB
in this chapter - Don't forget to add
return
for async test - The
set(Ref)
will reject on permission deny (not meeting the validation/authorization rules) - Use
goOffline(Database)
to disconnect, in afterAll to avoid the errorA worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks
- Import from bundle
firebase
, not@firebase
, it's for supportingfirebase
for now (found on npm) - No need to explicitly create instance in
.test.ts
, it seems will run all written code(unused var/import) without chunking/bundling
Realtime Database Rules#
- @2021-10-04
- Quick guide
- Full API
- PATH:In
ref()
, for the string parameterpath
, value\PATH\
,\PATH
,PATH\
,PATH
are the same.
Error Handling#
- @2021-10-05
- FirebaseError
- Auth Error codes
Issue on AuthError
interface#
- @2021-10-10
- "firebase": "^9.1.2" with TypeScript
- The
AuthError
with error codeAuthErrorCodes.NEED_CONFIRMATION === "auth/account-exists-with-different-credential"
has doesn't hasAuthError
props(appName, email, _tokenResponse
) on Official Doc - Two files in
node_modules\@firebase\
:auth\dist\auth-public.d.ts
andutil\dist\src\errors.d.ts
indicate that either theAuthError
is not correctly extended, or theAuthError
get fromsignInWithPopup()
method is incorrectly structured. I think it is the first one. - Created an issue and a PR on Firebase JS Official Repo
Firebase Local Emulator Suite#
- @2021-10-24
- Command
firebase emulators:start
don't have to run on the top level folder (which has subfolderfunction
). Running insidefunction
folder has same effect. - To test database, firestore, etc. Needs to configure it in
firebase init emulators
. Otherwise the cloud function will run with prod env.
Firebase API key security#
- @2021-10-24
-
The environment variable in
.env
is not hidden. It's possible to see them in source code. For example: I searched a random firebase based app on awwwards.com and found their API keyApp param of rebirth-from-the-ashes
```JavaScript initializeApp({ apiKey: "AIzaSyBE8OS5wnsgMGoySEgB7ShY8Jog5Z2S*\*\*first-three-capital-letters-in-week-in-spanish", authDomain: "rebirth-from-the-ashes.firebaseapp.com", projectId: "rebirth-from-the-ashes", storageBucket: "rebirth-from-the-ashes.appspot.com", messagingSenderId: "203993697*6!+6", appId: "1:20399369730:web:11099e26c37cdae998011*second-lowercase-letter", measurementId: "G-LT6R02TJK*letter-for-three" }) ```
- We can see firebase API key in
main.*.chunk.js
created byCRA
.
- For security, we can Regenerate Web API key of Google Firebase
- We can restrict the origin websites allowed to use the firebase app in Google Cloud Platform. In this way even knowing API key, there won't be much damage.
Extension for Storage rules#
- @2021-11-03
- Used toba.vsfire. File name (for
VSC
lang detect)*.rule
Fetch storage resource without login#
- @2021-11-03
- With Google Cloud Platform - Credentials set to "HTTP referrers" it's still possible to access the storage resource. Answer on
SO
Test cloud function locally#
- @2021-11-05
- Docs: the Function chapter unit-testing didn't specify how to run it(file structure, CLI
yarn test
failure withfunction/test/index.test.js
). Move to emulator suite chapter. - Docs: functions/get-started and emulator-suite/connect_and_prototype
- [ ] Didn't finish this topic. Turned to Algorand