Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui)!: add email verification and allow to unlink social provider…
…s from profile screen (#8358) * implement unlink providers * export only ProfileScreen * implement email verification * drop unused parameter * fix analyzer * Update packages/flutterfire_ui/lib/src/auth/email_verification.dart * Update packages/flutterfire_ui/example/lib/main.dart * properly fix pr review comment
- Loading branch information
Showing
15 changed files
with
794 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/flutterfire_ui/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/flutterfire_ui/lib/src/auth/email_verification.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:firebase_dynamic_links/firebase_dynamic_links.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
enum EmailVerificationState { | ||
unresolved, | ||
unverified, | ||
dismissed, | ||
sending, | ||
pending, | ||
sent, | ||
verified, | ||
failed, | ||
} | ||
|
||
class EmailVerificationService extends ValueNotifier<EmailVerificationState> { | ||
final FirebaseAuth auth; | ||
|
||
EmailVerificationService(this.auth) | ||
: super(EmailVerificationState.unresolved); | ||
|
||
User get user => auth.currentUser!; | ||
EmailVerificationState get state => value; | ||
|
||
Exception? error; | ||
|
||
bool _isMobile(TargetPlatform platform) { | ||
return platform == TargetPlatform.android || platform == TargetPlatform.iOS; | ||
} | ||
|
||
Future<void> reload() async { | ||
await user.reload(); | ||
if (user.emailVerified) { | ||
value = EmailVerificationState.verified; | ||
} else { | ||
value = EmailVerificationState.unverified; | ||
} | ||
} | ||
|
||
void dismiss() { | ||
value = EmailVerificationState.dismissed; | ||
} | ||
|
||
Future<void> sendVerificationEmail( | ||
TargetPlatform platform, | ||
ActionCodeSettings? actionCodeSettings, | ||
) async { | ||
value = EmailVerificationState.sending; | ||
try { | ||
await user.sendEmailVerification(actionCodeSettings); | ||
} on Exception catch (e) { | ||
error = e; | ||
value = EmailVerificationState.failed; | ||
return; | ||
} | ||
|
||
if (_isMobile(platform)) { | ||
value = EmailVerificationState.pending; | ||
final linkData = await FirebaseDynamicLinks.instance.onLink.first; | ||
|
||
try { | ||
final code = linkData.link.queryParameters['oobCode']!; | ||
await auth.checkActionCode(code); | ||
await auth.applyActionCode(code); | ||
await user.reload(); | ||
value = EmailVerificationState.verified; | ||
} on Exception catch (err) { | ||
error = err; | ||
value = EmailVerificationState.failed; | ||
} | ||
} else { | ||
value = EmailVerificationState.sent; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.