Created
December 8, 2021 02:18
-
-
Save csells/3f874c579ecb080acf7f029b01d14589 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import 'package:flutter/material.dart'; | |
import 'package:firebase_core/firebase_core.dart'; | |
import 'package:firebase_auth/firebase_auth.dart'; | |
import 'package:flutterfire_ui/auth.dart'; | |
import 'firebase_options.dart'; | |
Future<void> main() async { | |
WidgetsFlutterBinding.ensureInitialized(); | |
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) => MaterialApp( | |
home: AuthenticationGate(), | |
); | |
} | |
class AuthenticationGate extends StatelessWidget { | |
const AuthenticationGate({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) => StreamBuilder<User?>( | |
stream: FirebaseAuth.instance.authStateChanges(), | |
builder: (context, snapshot) { | |
// User is not signed in - show a sign-in screen | |
if (!snapshot.hasData) { | |
return SignInScreen( | |
providerConfigs: [ | |
EmailProviderConfiguration(), | |
GoogleProviderConfiguration( | |
clientId: 'xxxx-xxxx.apps.googleusercontent.com', | |
), | |
], | |
); | |
} | |
return HomePage(); // show your app’s home page after login | |
}, | |
); | |
} |
Check out the flutterfire_ui plugin and it's support for Google Sign-in: https://firebase.flutter.dev/docs/ui/auth/configuring-providers#google
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Did this work, my google sign in does not do anything. It just validates and brings me back to the sign in page. Is there something that i missed.
Also where did u get the client id from?
Thanks a ton