1
0
mirror of https://github.com/flutter/samples.git synced 2026-05-08 16:06:40 +00:00

[web_dashboard] add logout (#447)

* logout wip

* Use AnimatedSwitcher, change lingo from "login" to signIn"

* add automatic sign-in

* fix flashing sign in button

* sign out of FirebaseAuth and GoogleSignIn

* formatting

* change isSignedIn() to getter

* Add error handling for sign in

* improve error handling at login screen
This commit is contained in:
John Ryan
2020-06-01 14:39:06 -07:00
committed by GitHub
parent 46a3f2dd09
commit 8a9bcfa113
7 changed files with 218 additions and 55 deletions

View File

@@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/services.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:firebase_auth/firebase_auth.dart' hide FirebaseUser;
@@ -11,9 +12,20 @@ class FirebaseAuthService implements Auth {
final GoogleSignIn _googleSignIn = GoogleSignIn();
final FirebaseAuth _auth = FirebaseAuth.instance;
Future<bool> get isSignedIn => _googleSignIn.isSignedIn();
Future<User> signIn() async {
try {
return await _signIn();
} on PlatformException catch (e) {
print('Unable to sign in: $e');
throw SignInException();
}
}
Future<User> _signIn() async {
GoogleSignInAccount googleUser;
if (await _googleSignIn.isSignedIn()) {
if (await isSignedIn) {
googleUser = await _googleSignIn.signInSilently();
} else {
googleUser = await _googleSignIn.signIn();
@@ -30,7 +42,10 @@ class FirebaseAuthService implements Auth {
}
Future<void> signOut() async {
await _auth.signOut();
await Future.wait([
_auth.signOut(),
_googleSignIn.signOut(),
]);
}
}
@@ -39,3 +54,4 @@ class _FirebaseUser implements User {
_FirebaseUser(this.uid);
}