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

Issue #462 fix : Add new method that returns the logged-in user as Promise :

Open harshshredding opened this issue 3 years ago • 9 comments

Issue https://github.com/firebase/firebase-js-sdk/issues/462 Hi, firebase team! I am sure this pull-request is far from complete since I lack an understanding of the codebase.

onAuthStateChanged has the following caveats that seem to be making it difficult for new-comers to get started with firebase-auth :

  • The method name doesn't clearly indicate a very common use-case: getting the current user info. Also, the method name implies that some state has to be changed in order for the callback to be triggered, but the callback is also triggered when auth is not pending (no user is logged in).
  • Callbacks have caveats when compared to promises, which can be chained and utilized with the async keyword.

I was asked to tag @avolkovi and @bojeil-google.

harshshredding avatar Jan 13 '21 22:01 harshshredding

⚠️ No Changeset found

Latest commit: 6c56c980abd2f5dd5b512d59103092ad53b1fd56

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Jan 13 '21 22:01 changeset-bot[bot]

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

google-cla[bot] avatar Jan 13 '21 22:01 google-cla[bot]

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

google-cla[bot] avatar Jan 13 '21 22:01 google-cla[bot]

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

google-cla[bot] avatar Jan 14 '21 00:01 google-cla[bot]

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

google-cla[bot] avatar Jan 14 '21 02:01 google-cla[bot]

Hi @harshshredding, thank you very much for this pull request! API changes of this nature go through an internal process for approval. I'm sponsoring this and will get back to you in a few weeks!

sam-gc avatar Jan 28 '21 00:01 sam-gc

Hi @harshshredding, thanks so much for your patience. After an internal review, we've concluded that this function should not itself return a user object. Instead, the function should return a Promise<void> that resolves when the auth state is ready and settled (i.e. when reading auth().currentUser is valid).

That function should be called authStateReady() and have the following signature:

interface Auth {
  authStateReady(): Promise<void>;
}

The function could then be used like:

async function doStuff() {
  await firebase.auth().authStateReady();
  nowSafeToRead(firebase.auth().currentUser);
}

I believe your function in this PR can be easily updated to do the same thing but simply not resolve with any value.

sam-gc avatar Jun 03 '21 18:06 sam-gc

@sam-gc I will update the PR very soon. Thanks a lot for the feedback.

harshshredding avatar Oct 06 '21 21:10 harshshredding

wow

Deliana90 avatar Jul 08 '22 12:07 Deliana90

@harshshredding

https://github.com/firebase/firebase-js-sdk/pull/4288#event-8542325400

??? What happened?

Malix-Labs avatar Mar 18 '23 23:03 Malix-Labs

Sorry guys, I don't have the bandwidth. @sam-gc can you assign this to someone else?

harshshredding avatar Mar 21 '23 18:03 harshshredding

Sorry guys, I don't have the bandwidth. Sam can you assign this to someone else?

We got API review feedback to expose this slightly differently. We are working on it in https://github.com/firebase/firebase-js-sdk/pull/7384

prameshj avatar Jul 05 '23 19:07 prameshj