Skip to content

First pass at polyfill #3517

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
Aug 5, 2020
Merged

First pass at polyfill #3517

merged 2 commits into from
Aug 5, 2020

Conversation

avolkovi
Copy link
Contributor

@avolkovi avolkovi commented Jul 30, 2020

I had to refactor our AuthImpl a lot to get this to work, TLDR we have:

types:

  • externs.Auth (new public types)
  • compat.FirebaseAuth (old public types)
  • auth-exp/AuthCore (at most externs.Auth | compat.FirebaseAuth, but in reality it's just pared down to the core fields)
  • auth-exp/Auth extends auth-exp/AuthCore (auth-exp/AuthCore + private methods)

implementations:

  • AuthImplCompat implements auth-exp/Auth
  • AuthImpl extends AuthImplCompat implements externs.Auth
  • auth-compat-exp/Auth extends AuthImplCompat implements compat.FirebaseAuth

notes:

  • I changed most usage of auth-exp/Auth -> auth-exp/AuthCore, since it's now a strict subset of externs.Auth we can drop a ton of casts
  • Tests should only use TestAuth since it implements both auth-exp/Auth and externs.Auth and doesn't require casting to either
  • The few places we have that actually depend on private methods in auth-exp/Auth should use the unsafe _castAuth and ensure they never call setPersistence, onAuthStateChanged and onIdTokenStateChanged since those methods could have different signatures depending on whether an instance of AuthImpl or auth-compat-exp/Auth was passed in.
  • We need to perform an unsafe cast of auth-compat-exp/Auth -> externs.Auth before calling from the polyfill to the new implementation, this cast is unsafe since the signature on the 3 above mentioned changes, hence we must avoid ever calling those methods directly
  • AuthImplCompat is generic so currentUser types correctly to the right implementation
  • AuthImplCompat constructor takes a UserProvider so it can instantiate users of the right class

heuristics to follow:

  • If you are taking input from a user, use externs.Auth
  • If you are a private method, use auth-exp/AuthCore (true for 99% cases that only need auth for auth.name), otherwise use auth-exp/Auth if you or a dependency call one of the _ methods on auth
  • If you are a test, use TestAuth
  • Converting from externs.Auth -> auth-exp/AuthCore is free
  • Converting from externs.Auth -> auth-exp/Auth is achieved through an unsafe cast by calling _castAuth()
  • Converting from auth-compat-exp/Auth -> externs.Auth is achieved through an unsafe cast by calling this.asExtern()
  • Never ever ever call setPersistence, onAuthStateChanged or onIdTokenStateChanged from our code since you have no idea which implementation you're holding on to, use the equivalent _ prefixed methods if you need to call them. Only the user (or integration tests) get to call these directly.

@avolkovi avolkovi requested a review from sam-gc July 30, 2020 18:53
@changeset-bot
Copy link

changeset-bot bot commented Jul 30, 2020

💥 No Changeset

Latest commit: 43c0c18

Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂

If these changes should be published to npm, 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

@avolkovi avolkovi force-pushed the avolkovi/polyfill branch from 7da9610 to 7e0f292 Compare July 30, 2020 18:55
@avolkovi avolkovi force-pushed the avolkovi/polyfill branch 2 times, most recently from ba9b8e7 to 5efdcbc Compare July 31, 2020 20:18
@avolkovi avolkovi marked this pull request as ready for review July 31, 2020 20:19
@avolkovi avolkovi force-pushed the avolkovi/polyfill branch 2 times, most recently from 044fba4 to 2935024 Compare July 31, 2020 23:41
pendingToken,
nonce
} = _tokenResponse as SignInWithIdpResponse;
switch (providerId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just have all of these in the switch statements call Provider.credentialFromResult() like you do for phone auth

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, I guess we didn't have these before and I was just copying the old implementation... we should add one to OAuthProvider for the last bit here

@avolkovi avolkovi force-pushed the avolkovi/polyfill branch from ed42bf2 to 43c0c18 Compare August 3, 2020 18:32
@google-oss-bot
Copy link
Contributor

Binary Size Report

Affected SDKs

No changes between base commit (937f335) and head commit (53d294d).

Test Logs

@avolkovi avolkovi merged commit 9cb7cd8 into auth-next Aug 5, 2020
@avolkovi avolkovi deleted the avolkovi/polyfill branch August 5, 2020 15:49
avolkovi added a commit that referenced this pull request Aug 6, 2020
* First pass at polyfill

* PR Feedback
avolkovi added a commit that referenced this pull request Aug 10, 2020
* First pass at polyfill

* PR Feedback
sam-gc pushed a commit that referenced this pull request Sep 1, 2020
* First pass at polyfill

* PR Feedback
@firebase firebase locked and limited conversation to collaborators Sep 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants