-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: further improve user experience and clarify auth procedures
- Loading branch information
1 parent
613fb24
commit d8c04de
Showing
16 changed files
with
244 additions
and
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
import 'package:async/async.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:google_sign_in/google_sign_in.dart'; | ||
import 'package:thank_you_token/services/auth/auth_service.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
import 'package:thank_you_token/services/drive/drive_service.dart'; | ||
|
||
// If there is an initial login, the user is googleSignIn.currentUser. Return | ||
// that, but afterwards listen to googleSignIn.onCurrentUserChanged and return | ||
// the new user. | ||
final userProvider = StreamProvider<GoogleSignInAccount?>( | ||
(ref) => StreamGroup.merge([ | ||
Stream.value(googleSignIn.currentUser), | ||
googleSignIn.onCurrentUserChanged | ||
]), | ||
); | ||
part 'user_provider.g.dart'; | ||
|
||
@Riverpod(keepAlive: true) | ||
class User extends _$User { | ||
@override | ||
GoogleSignInAccount? build() { | ||
final initialUser = ref.watch(initialUserProvider); | ||
if (initialUser != null) { | ||
return initialUser; | ||
} else { | ||
DriveServiceApi().onCurrentUserChanged().listen((user) { | ||
state = user; | ||
}); | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
@Riverpod(keepAlive: true) | ||
GoogleSignInAccount? initialUser(InitialUserRef ref) => null; |
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
Oops, something went wrong.