@@ -6,11 +6,13 @@ This repository provides a standardized way to handle user authentication. It ab
66
77## Features
88
9- * ** Sign Up:** Register new users.
10- * ** Sign In:** Authenticate existing users.
11- * ** Sign Out:** Log out users.
12- * ** Delete:** Delete the user account.
13- * ** Authentication State Management:** Stream authentication state changes.
9+ * ** Passwordless Sign-in (Magic Link):** Send a sign-in link to an email address and complete the sign-in process using the link.
10+ * ** Google Sign-In:** Authenticate users via their Google account.
11+ * ** Anonymous Sign-In:** Allow users to sign in anonymously.
12+ * ** Sign Out:** Log out the current user.
13+ * ** Delete Account:** Delete the current user's account.
14+ * ** Authentication State:** Stream the current user's authentication state.
15+ * ** Current User Access:** Synchronously get the latest cached user.
1416
1517## Dependencies
1618
@@ -61,45 +63,75 @@ void main() async {
6163
6264 // Access the user stream.
6365 authenticationRepository.user.listen((user) {
64- print('User: ${user.id}');
66+ print('User ID : ${user.id}, Status: ${user.status }');
6567 });
6668
67- // Sign in with email and password (replace with actual credentials).
69+ // Get the current user synchronously (might be the default empty user initially)
70+ print('Current User ID: ${authenticationRepository.currentUser.id}');
71+
72+ // --- Email Link Sign-In Flow ---
73+ const email = 'test@example.com';
6874 try {
69- await authenticationRepository.signInWithEmailAndPassword(
70- email: 'test@example.com',
71- password: 'password',
75+ // 1. Send the link
76+ await authenticationRepository.sendSignInLinkToEmail(email: email);
77+ print('Sign-in link sent to $email');
78+
79+ // 2. In a separate part of your app (e.g., after user clicks the link),
80+ // get the emailLink and complete sign-in:
81+ const emailLink = 'https://your-app.link/signIn?oobCode=...'; // Replace with actual link
82+ await authenticationRepository.signInWithEmailLink(
83+ email: email,
84+ emailLink: emailLink,
7285 );
86+ print('Signed in with email link successfully!');
87+ } on SendSignInLinkException catch (e) {
88+ print('Failed to send sign-in link: $e');
89+ } on InvalidSignInLinkException catch (e) {
90+ print('Failed to sign in with email link (invalid link): $e');
91+ } on UserNotFoundException catch (e) {
92+ print('Failed to sign in with email link (user not found): $e');
7393 } catch (e) {
74- print('Sign in failed: $e');
94+ print('Email link sign- in failed: $e');
7595 }
7696
77- // Sign in with google.
97+ // --- Google Sign-In ---
7898 try {
7999 await authenticationRepository.signInWithGoogle();
100+ print('Signed in with Google successfully!');
101+ } on GoogleSignInException catch (e) {
102+ print('Google sign-in failed: $e');
80103 } catch (e) {
81- print('Sign in failed: $e');
104+ print('Google sign- in failed with unexpected error : $e');
82105 }
83106
84- // Sign in anonymously.
107+ // --- Anonymous Sign-In ---
85108 try {
86109 await authenticationRepository.signInAnonymously();
110+ print('Signed in anonymously successfully!');
111+ } on AnonymousLoginException catch (e) {
112+ print('Anonymous sign-in failed: $e');
87113 } catch (e) {
88- print('Sign in failed: $e');
114+ print('Anonymous sign- in failed with unexpected error : $e');
89115 }
90116
91- // Sign out.
117+ // --- Sign Out ---
92118 try {
93119 await authenticationRepository.signOut();
94- } catch (e) {
120+ print('Signed out successfully!');
121+ } on LogoutException catch (e) {
95122 print('Sign out failed: $e');
123+ } catch (e) {
124+ print('Sign out failed with unexpected error: $e');
96125 }
97126
98- // Delete Account.
127+ // --- Delete Account ---
99128 try {
100129 await authenticationRepository.deleteAccount();
101- } catch (e) {
130+ print('Account deleted successfully!');
131+ } on DeleteAccountException catch (e) {
102132 print('Delete account failed: $e');
133+ } catch (e) {
134+ print('Delete account failed with unexpected error: $e');
103135 }
104136}
105137
0 commit comments