+
Skip to content

Enable customizing FirebaseOptions #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2023

Conversation

shirakawayohane
Copy link
Contributor

@shirakawayohane shirakawayohane commented Jan 19, 2023

Currently, it seems to be that we can not setup FirebaseOption freely because the code of building FirebaseOptions is hard coded.

(defrecord FirebaseAdmin [service-account-key-path ^FirebaseApp app]
component/Lifecycle
(start [this]
(let [f (io/file service-account-key-path)]
(when-not (.canRead f)
(throw (IllegalArgumentException. "Firebase service account key file does not exist")))
(with-open [is (io/input-stream f)]
(assoc this
:app (let [opts (-> (FirebaseOptions/builder)
(.setCredentials (GoogleCredentials/fromStream is))
(.build))]
(FirebaseApp/initializeApp opts))))))

It might be problem when we want to use firebase storage (for example) from firebase-admin-sdk.

So I added additional option named options-builder to enable custom setup of FirebaseApp initialization.

In the case when you want to use firebase storage from admin-sdk, for example, you can use this option like below.

(tc.firebase/map->FirebaseAdmin (assoc (:firebase config)
                                                :options-builder
                                                (-> (FirebaseOptions/builder)
                                                    (.setStorageBucket (get-in config [:firebase :storageBucket])))))

;; assuming that
;; - toyokumo.commons.experimental.firebase.admin-sdk is required as tc.firebase
;; - `config` is a map containing a value, which represents FirebaseAdmin record values, with key `:firebase`

@shirakawayohane shirakawayohane marked this pull request as ready for review January 19, 2023 03:53
@shirakawayohane shirakawayohane requested review from syunta, makinoshi and liquidz and removed request for syunta and makinoshi January 19, 2023 03:54
@shirakawayohane shirakawayohane force-pushed the setup-firebase-option-other-than-credentials branch from fd883a5 to f0f8119 Compare January 19, 2023 04:50
@shirakawayohane shirakawayohane changed the title Enable set-up FirebaseOptions other than about credentials. Enable customizing FirebaseOptions Jan 19, 2023
@shirakawayohane shirakawayohane force-pushed the setup-firebase-option-other-than-credentials branch from f0f8119 to de9f416 Compare January 19, 2023 04:53
Copy link
Contributor

@liquidz liquidz left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@shirakawayohane
Copy link
Contributor Author

Thank you!

@shirakawayohane shirakawayohane merged commit c6100b4 into main Jan 20, 2023
@shirakawayohane shirakawayohane deleted the setup-firebase-option-other-than-credentials branch January 20, 2023 04:41
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.

4 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载