generated from GDGVIT/template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
107 additions
and
151 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"cSpell.words": [ | ||
"prefs", | ||
"riverpod" | ||
] | ||
} |
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
18 changes: 18 additions & 0 deletions
18
book_keeper/lib/auth/presentation/controllers/custom_auth_login_controller.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,18 @@ | ||
import 'package:book_keeper/auth/repository/custom_auth_repository.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
part 'custom_auth_login_controller.g.dart'; | ||
|
||
@riverpod | ||
class CustomAuthLoginController extends _$CustomAuthLoginController { | ||
@override | ||
Future<void> build() async {} | ||
|
||
Future<void> logInWithEmailAndPassword({ | ||
required String email, | ||
required String password, | ||
}) async { | ||
final authRepo = ref.read(customAuthRepoProvider); | ||
await authRepo.logInWithEmailAndPassword(email: email, password: password); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
book_keeper/lib/auth/presentation/controllers/custom_auth_signup_controller.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,23 @@ | ||
import 'package:book_keeper/auth/repository/custom_auth_repository.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
part 'custom_auth_signup_controller.g.dart'; | ||
|
||
@riverpod | ||
class CustomAuthLoginController extends _$CustomAuthLoginController { | ||
@override | ||
Future<void> build() async {} | ||
|
||
Future<void> signUpWithEmailAndPassword({ | ||
required String name, | ||
required String email, | ||
required String password, | ||
}) async { | ||
final authRepo = ref.read(customAuthRepoProvider); | ||
await authRepo.signUpWithEmailAndPassword( | ||
name: name, | ||
email: email, | ||
password: password, | ||
); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...on/controllers/login_page_controller.dart → ...n/controllers/google_auth_controller.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
27 changes: 0 additions & 27 deletions
27
book_keeper/lib/auth/presentation/controllers/login_page_controller.g.dart
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
49 changes: 49 additions & 0 deletions
49
book_keeper/lib/auth/repository/firebase_auth_repository.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,49 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:google_sign_in/google_sign_in.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
part 'firebase_auth_repository.g.dart'; | ||
|
||
@riverpod | ||
Stream<User?> authStatusChanges(AuthStatusChangesRef ref) { | ||
return FirebaseAuth.instance.authStateChanges(); | ||
} | ||
|
||
abstract class FireAuthRepo { | ||
User? currentUser(); | ||
Future<void> signInWithGoogle(); | ||
Future<void> signOut(); | ||
} | ||
|
||
class FirebaseAuthRepo implements FireAuthRepo { | ||
final GoogleSignIn _googleSignIn = GoogleSignIn(); | ||
|
||
@override | ||
Future<void> signInWithGoogle() async { | ||
final googleUser = await _googleSignIn.signIn(); | ||
if (googleUser == null) { | ||
return; | ||
} | ||
final googleAuth = await googleUser.authentication; | ||
final credential = GoogleAuthProvider.credential( | ||
accessToken: googleAuth.accessToken, | ||
idToken: googleAuth.idToken, | ||
); | ||
await FirebaseAuth.instance.signInWithCredential(credential); | ||
} | ||
|
||
@override | ||
Future<void> signOut() async { | ||
await FirebaseAuth.instance.signOut(); | ||
} | ||
|
||
@override | ||
User? currentUser() { | ||
return FirebaseAuth.instance.currentUser; | ||
} | ||
} | ||
|
||
@riverpod | ||
FireAuthRepo firebaseAuthRepo(FirebaseAuthRepoRef ref) { | ||
return FirebaseAuthRepo(); | ||
} |