Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added silent sign in #9

Open
wants to merge 1 commit into
base: Development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions student_agenda/lib/Utilities/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ class AuthService {
return _googleSignIn.currentUser.authHeaders;
}

Future<FirebaseUser> googleSilentSignIn() async {
loading.add(true);
print("Signing in Silently");
GoogleSignInAccount googleUser = await _googleSignIn.signInSilently();//.whenComplete(() => loading.add(false));
GoogleSignInAuthentication googleAuth = await googleUser.authentication;
firebaseUser = (await _auth.signInWithCredential(
GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken
)
)).user;

loading.add(false);
return firebaseUser;
}


void signOut() {
_auth.signOut();
Expand Down
4 changes: 2 additions & 2 deletions student_agenda/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
isDefaultAction: true,
child: Text('Ok'),
onPressed: () async {
Future<FirebaseUser> user = authService.googleSignIn();
Future<FirebaseUser> user = authService.googleSilentSignIn();
Navigator.of(context, rootNavigator: true).pop();
await user.then((user) =>
Navigator.push(
Expand All @@ -146,7 +146,7 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
);

selectNotificationSubject.stream.listen((String payload) async {
Future<FirebaseUser> user = authService.googleSignIn();
Future<FirebaseUser> user = authService.googleSilentSignIn();
Navigator.of(context, rootNavigator: true).pop();
await user
.then((user) =>
Expand Down