Skip to content

Commit 8e7f774

Browse files
author
CDDelta
authored
[firebase_auth] implement missing auth functionality for web (flutter#1864)
* implement missing auth functionality for web * add changelog * bump pubspec version * add missing method to changelog * fix interface
1 parent a0b51b5 commit 8e7f774

3 files changed

Lines changed: 27 additions & 17 deletions

File tree

packages/firebase_auth/firebase_auth_web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.2
2+
3+
* Implement `fetchSignInMethodsForEmail`, `isSignInWithEmailLink`, `signInWithEmailAndLink`, and `sendLinkToEmail`.
4+
15
## 0.1.1+4
26

37
* Prevent `null` users (unauthenticated) from breaking the `onAuthStateChanged` Stream.

packages/firebase_auth/firebase_auth_web/lib/firebase_auth_web.dart

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,8 @@ class FirebaseAuthWeb extends FirebaseAuthPlatform {
147147

148148
@override
149149
Future<List<String>> fetchSignInMethodsForEmail(String app, String email) {
150-
// TODO(hterkelsen): Use `fetchSignInMethodsForEmail` once
151-
// https://github.com/FirebaseExtended/firebase-dart/issues/272
152-
// is resolved.
153-
throw UnimplementedError('fetchSignInMethodsForEmail');
150+
final firebase.Auth auth = _getAuth(app);
151+
return auth.fetchSignInMethodsForEmail(email);
154152
}
155153

156154
@override
@@ -162,8 +160,6 @@ class FirebaseAuthWeb extends FirebaseAuthPlatform {
162160

163161
@override
164162
Future<PlatformIdTokenResult> getIdToken(String app, bool refresh) async {
165-
// TODO(hterkelsen): `package:firebase` added `getIdTokenResult` in
166-
// version 7.0.0. Use it here once that is published.
167163
final firebase.Auth auth = _getAuth(app);
168164
final firebase.User currentUser = auth.currentUser;
169165
final firebase.IdTokenResult idTokenResult =
@@ -173,10 +169,8 @@ class FirebaseAuthWeb extends FirebaseAuthPlatform {
173169

174170
@override
175171
Future<bool> isSignInWithEmailLink(String app, String link) {
176-
// TODO(hterkelsen): Implement this once
177-
// https://github.com/FirebaseExtended/firebase-dart/issues/273
178-
// is resolved.
179-
throw UnimplementedError('isSignInWithEmailLink');
172+
final firebase.Auth auth = _getAuth(app);
173+
return Future.value(auth.isSignInWithEmailLink(link));
180174
}
181175

182176
@override
@@ -232,9 +226,20 @@ class FirebaseAuthWeb extends FirebaseAuthPlatform {
232226
String androidPackageName,
233227
bool androidInstallIfNotAvailable,
234228
String androidMinimumVersion}) {
235-
// TODO(hterkelsen): File issue with `package:firebase` to show
236-
// `sendSignInLinkToEmail`.
237-
throw UnimplementedError('sendLinkToEmail');
229+
final firebase.Auth auth = _getAuth(app);
230+
final actionCodeSettings = firebase.ActionCodeSettings(
231+
url: url,
232+
handleCodeInApp: handleCodeInApp,
233+
iOS: firebase.IosSettings(
234+
bundleId: iOSBundleID,
235+
),
236+
android: firebase.AndroidSettings(
237+
packageName: androidPackageName,
238+
installApp: androidInstallIfNotAvailable,
239+
minimumVersion: androidMinimumVersion,
240+
),
241+
);
242+
return auth.sendSignInLinkToEmail(email, actionCodeSettings);
238243
}
239244

240245
@override
@@ -280,9 +285,10 @@ class FirebaseAuthWeb extends FirebaseAuthPlatform {
280285
@override
281286
Future<PlatformAuthResult> signInWithEmailAndLink(
282287
String app, String email, String link) async {
283-
// TODO(hterkelsen): Use signInWithEmailLink once 7.0.0 of package:firebase
284-
// is released.
285-
throw UnimplementedError('signInWithEmailAndLink');
288+
final firebase.Auth auth = _getAuth(app);
289+
final firebase.UserCredential userCredential =
290+
await auth.signInWithEmailLink(email, link);
291+
return _fromJsUserCredential(userCredential);
286292
}
287293

288294
@override

packages/firebase_auth/firebase_auth_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: firebase_auth_web
22
description: The web implementation of firebase_auth
33
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_auth/firebase_auth_web
4-
version: 0.1.1+4
4+
version: 0.1.2
55

66
flutter:
77
plugin:

0 commit comments

Comments
 (0)