Cleanup and add GetIt
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
|
||||
import 'package:como_gasto/auth_providers/google_auth_provider.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
|
||||
enum LoginProvider {
|
||||
GOOGLE,
|
||||
TWITTER,
|
||||
FACEBOOK,
|
||||
}
|
||||
|
||||
abstract class AuthenticationProvider {
|
||||
Future<AuthCredential> handleSignIn();
|
||||
void logout();
|
||||
|
||||
static AuthenticationProvider createAuthProvider(LoginProvider provider) {
|
||||
switch (provider) {
|
||||
case LoginProvider.GOOGLE:
|
||||
return GoogleAuthenticationProvider();
|
||||
break;
|
||||
case LoginProvider.TWITTER:
|
||||
// TODO: Handle this case.
|
||||
break;
|
||||
case LoginProvider.FACEBOOK:
|
||||
// TODO: Handle this case.
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
import 'package:como_gasto/auth_providers/auth_provider.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
|
||||
class GoogleAuthenticationProvider implements AuthenticationProvider {
|
||||
final GoogleSignIn _googleSignIn = GoogleSignIn();
|
||||
|
||||
@override
|
||||
Future<AuthCredential> handleSignIn() async {
|
||||
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
|
||||
if (googleUser == null) {
|
||||
return null;
|
||||
}
|
||||
final GoogleSignInAuthentication googleAuth =
|
||||
await googleUser.authentication;
|
||||
|
||||
final AuthCredential credential = GoogleAuthProvider.getCredential(
|
||||
accessToken: googleAuth.accessToken,
|
||||
idToken: googleAuth.idToken,
|
||||
);
|
||||
|
||||
return credential;
|
||||
}
|
||||
|
||||
@override
|
||||
void logout() {
|
||||
_googleSignIn.signOut();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user