Skip to content

Commit 3a144d1

Browse files
author
Giovanni Terlingen
committed
Add email link sign in bindings (#261)
1 parent 49f3613 commit 3a144d1

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

packages/firebase-dart/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- **BREAKING** renamed `AuthCredential` into `OAuthCredential` to align with JS API
44
- Added `idToken`, `accessToken` and `secret` to `OAuthCredential`
5+
- Added support for Email Link authentication
56

67
## 6.0.0
78

packages/firebase-dart/lib/src/auth.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,20 @@ class Auth extends JsObjectWrapper<AuthJsImpl> {
370370
handleThenable(jsObject.getRedirectResult())
371371
.then((u) => UserCredential.fromJsObject(u));
372372

373+
/// Sends a sign-in email link to the user with the specified email.
374+
///
375+
/// The sign-in operation has to always be completed in the app unlike other out
376+
/// of band email actions (password reset and email verifications). This is
377+
/// because, at the end of the flow, the user is expected to be signed in and
378+
/// their Auth state persisted within the app.
379+
///
380+
/// To complete sign in with the email link, call
381+
/// [Auth.signInWithEmailLink] with the email address and
382+
/// the email link supplied in the email sent to the user.
383+
Future sendSignInLinkToEmail(String email,
384+
[ActionCodeSettings actionCodeSettings]) =>
385+
handleThenable(jsObject.sendSignInLinkToEmail(email, actionCodeSettings));
386+
373387
/// Sends a password reset e-mail to the given [email].
374388
/// To confirm password reset, use the [Auth.confirmPasswordReset].
375389
///
@@ -467,6 +481,11 @@ class Auth extends JsObjectWrapper<AuthJsImpl> {
467481
handleThenable(jsObject.signInWithEmailAndPassword(email, password))
468482
.then((u) => UserCredential.fromJsObject(u));
469483

484+
/// Signs in using [email] and [emailLink] link.
485+
Future<UserCredential> signInWithEmailLink(String email, String emailLink) =>
486+
handleThenable(jsObject.signInWithEmailLink(email, emailLink))
487+
.then((u) => UserCredential.fromJsObject(u));
488+
470489
/// Asynchronously signs in using a phone number in E.164 format
471490
/// (e.g. +16505550101).
472491
///

packages/firebase-dart/lib/src/interop/auth_interop.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ abstract class AuthJsImpl {
2929
[Func1 opt_error, Func0 opt_completed]);
3030
external Func0 onIdTokenChanged(nextOrObserver,
3131
[Func1 opt_error, Func0 opt_completed]);
32+
external PromiseJsImpl sendSignInLinkToEmail(String email,
33+
[ActionCodeSettings actionCodeSettings]);
3234
external PromiseJsImpl sendPasswordResetEmail(String email,
3335
[ActionCodeSettings actionCodeSettings]);
3436
external PromiseJsImpl setPersistence(String persistence);
@@ -42,6 +44,8 @@ abstract class AuthJsImpl {
4244
signInAndRetrieveDataWithCustomToken(String token);
4345
external PromiseJsImpl<UserCredentialJsImpl> signInWithEmailAndPassword(
4446
String email, String password);
47+
external PromiseJsImpl<UserCredentialJsImpl> signInWithEmailLink(
48+
String email, String emailLink);
4549
external PromiseJsImpl<ConfirmationResultJsImpl> signInWithPhoneNumber(
4650
String phoneNumber, ApplicationVerifierJsImpl applicationVerifier);
4751
external PromiseJsImpl<UserCredentialJsImpl> signInWithPopup(

0 commit comments

Comments
 (0)