firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

[FR]: A promise that will initialize firebase (pause the code until firebase is working)

Open Sameszop opened this issue 1 year ago • 4 comments

Description

  1. Before your firebase code can run, firebase always needs a few moments until it can run.

  2. Mostly used is OnAuthStateChanged() which executes the code when a user is found. However that does not work when there is no user or when the code that needs to know if there is a user starts immidiatly. So there is always a timing problem which can be hard to solve (To use a timer for example is not how you want the code to work)

  3. To have a promise like await initFirebase() that will wait until firebase is ready to be used would be fantastic.

Thank you for your time

API Proposal

No response

Firebase Product(s)

Performance

Sameszop avatar Aug 23 '24 08:08 Sameszop

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Aug 23 '24 08:08 google-oss-bot

Please provide more clarity about the request.

What specifically about FirebasePerformance needs this capability?

You mention OnAuthStateChanged(). What would you like to happen if there is no user logged in?

paulb777 avatar Aug 23 '24 13:08 paulb777

When you use OnAuthStateChanged, the first value that is returned is always null (because firebase is not yet initialized). So it would be generally nice to have a function/promise that you can run to make sure firebase is initialized before the code continues. Because if that would be the case, you can then just run const user = await auth.currentUser and then you would always know if a user is logged in (why I think that this would be better than just simply OnAuthStateChanged() is because the first value you get from OnAuthStateChanged() is always null no matter if the user is authenticated or not). My issue is not with a specific function, I just think that it would be easier to code with firebase when you could make sure that firebase is initialized and able to run and for that purpose OnAuthStateChanged is not ideal.

PS.: I am sorry when this sounds to complicated or when I am just missing something, if it helps I can send a .js file to make my point clearer


From: Paul Beusterien @.> Sent: Friday, August 23, 2024 3:46:37 PM To: firebase/firebase-ios-sdk @.> Cc: Sameszop @.>; Author @.> Subject: Re: [firebase/firebase-ios-sdk] [FR]: A promise that will initialize firebase (pause the code until firebase is working) (Issue #13533)

Please provide more clarity about the request.

What specifically about FirebasePerformance needs this capability?

You mention OnAuthStateChanged(). What would you like to happen if there is no user logged in?

— Reply to this email directly, view it on GitHubhttps://github.com/firebase/firebase-ios-sdk/issues/13533#issuecomment-2307133036, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BE3AROXLIXAJD3RDEDLJC5DZS44L3AVCNFSM6AAAAABM7WEYSKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBXGEZTGMBTGY. You are receiving this because you authored the thread.Message ID: @.***>

Sameszop avatar Aug 23 '24 15:08 Sameszop

Thanks for the clarification. I understand the request. It's a feature request for FirebaseAuth, not FirebasePerformance.

paulb777 avatar Aug 23 '24 15:08 paulb777

See discussion at https://github.com/firebase/firebase-ios-sdk/issues/13231#issuecomment-2323424347

paulb777 avatar Sep 01 '24 16:09 paulb777