Skip to content

[firebase_auth] implement missing auth functionality for web #1864

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 5 commits into from
Jan 29, 2020
Merged

[firebase_auth] implement missing auth functionality for web #1864

merged 5 commits into from
Jan 29, 2020

Conversation

CDDelta
Copy link

@CDDelta CDDelta commented Jan 24, 2020

Description

Implements the missing auth behavior for web except for verifyPhoneNumber.

Related Issues

#1682

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • If the pull request affects only one plugin, the PR title starts with the name of the plugin in brackets (e.g. [cloud_firestore])
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

Copy link
Contributor

@ditman ditman left a comment

Choose a reason for hiding this comment

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

@hterkelsen is going to love this. Thanks for the contribution @CDDelta!!

Comment on lines +233 to +240
iOS: firebase.IosSettings(
bundleId: iOSBundleID,
),
android: firebase.AndroidSettings(
packageName: androidPackageName,
installApp: androidInstallIfNotAvailable,
minimumVersion: androidMinimumVersion,
),
Copy link
Contributor

Choose a reason for hiding this comment

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

I was reading the documentation and... do we want to kick the user to the Android/iOS app from the web? This change kind of adds a requirement of setting up an iOSBundleID and an androidPackageName on a potentially web-only app.

Can these attributes be passed to the ActionCodeSettings conditionally? Does this handle null values gracefully, or does it cause an error?

Copy link
Author

Choose a reason for hiding this comment

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

You're right, we shouldn't force users to set up those attributes.

I can change to make this optional but it would require modifying the plugin to not assert that these attributes are non-null and update the native code to gracefully handle non-null values too to keep the api behavior consistent on all platforms.

Is that the route we want to go down or is there an alternative?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm deferring this one to @hterkelsen, he wrote the original implementation. IMO all these should be optional. I'm guessing in a web-only flow, those are never expected to be used, right?

Choose a reason for hiding this comment

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

Since these are already required parameters in package:firebase_auth I think it makes sense to use them like this. All this is saying is if the Android or iOS app is installed then the sign in link will attempt to open the app,

Copy link
Author

Choose a reason for hiding this comment

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

Maybe this is out of the scope of this PR but there is currently no way for users to not include an Android packageName or iOS bundleId.

Passing a null will cause the method to assert and passing an empty string will cause Firebase to throw an argument error. A possible hack might be to pass in a random string but that seems fragile and possibly dangerous.

I think it would be a good idea to allow users to opt out of certain platforms by passing null.

Comment on lines +289 to +290
final firebase.UserCredential userCredential =
await auth.signInWithEmailLink(email, link);
Copy link
Contributor

Choose a reason for hiding this comment

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

This might "Fail with an error if the email address is invalid or OTP in email link expires.". Docs.

Does that case need to be handled, or would that exception (?) propagate to the client app? (I've seen other places in the web plugin with a similar pattern... How do the Android/iOS versions behave in that case?)

Copy link
Author

Choose a reason for hiding this comment

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

Right now it looks like the function will throw a FirebaseError instance to the client which we will want to map to a PlatformException but that would require #1698 to land first.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yes, that 1698 is going to be handy. Thanks for pointing it out!

@@ -1,3 +1,7 @@
## 0.1.2

* Implement `fetchSignInMethodsForEmail`, `isSignInWithEmailLink`, and `sendLinkToEmail`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some unit tests? At least, it'd be interesting to have a test of the sad path of signInWithEmailLink, that codifies whatever is decided in this PR (whether it throws or catch + return null... whatever)

Copy link
Author

Choose a reason for hiding this comment

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

Do we need to do that? I believe the firebase-dart package will properly throw the expected FirebaseError instances which #1698 will map to our expected PlatformExceptions.

@CDDelta
Copy link
Author

CDDelta commented Jan 29, 2020

@hterkelsen what are the things I need to do to get this change merged? :)

Copy link

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

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

LGTM. I restarted a failing test. I'll merge once it goes green.

@harryterkelsen
Copy link

Never mind. The failure is unrelated and is being fixed in a separate PR.

@harryterkelsen harryterkelsen merged commit 8e7f774 into firebase:master Jan 29, 2020
@firebase firebase locked and limited conversation to collaborators Aug 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants