From 4d415845474307a43fdc404735344ed0876ca94b Mon Sep 17 00:00:00 2001 From: hunteraraujo Date: Fri, 15 Sep 2023 14:26:04 -0700 Subject: [PATCH] Implement FirebaseAuthView for Google and GitHub Sign-In This commit adds the `FirebaseAuthView` class, a Flutter widget that serves as the UI for user authentication using Google and GitHub. The class uses the `AuthService` to handle the actual sign-in logic. Features: - Added an OutlinedButton for Google Sign-In, styled with Google's colors and logo. - Added an OutlinedButton for GitHub Sign-In, styled with GitHub's colors and logo. - Integrated the `AuthService` methods for Google and GitHub sign-in. --- .../lib/views/auth/firebase_auth_view.dart | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 frontend/lib/views/auth/firebase_auth_view.dart diff --git a/frontend/lib/views/auth/firebase_auth_view.dart b/frontend/lib/views/auth/firebase_auth_view.dart new file mode 100644 index 00000000..813227b5 --- /dev/null +++ b/frontend/lib/views/auth/firebase_auth_view.dart @@ -0,0 +1,71 @@ +import 'package:flutter/material.dart'; +import 'package:auto_gpt_flutter_client/services/auth_service.dart'; + +class FirebaseAuthView extends StatelessWidget { + // TODO: This should be initialized in the main.dart instead of here + final AuthService _authService = AuthService(); + + FirebaseAuthView({super.key}); // Initialize the auth service + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + OutlinedButton( + onPressed: () async { + final user = await _authService.signInWithGoogle(); + if (user != null) { + print( + "Successfully signed in with Google: ${user.user?.displayName}"); + } + }, + style: OutlinedButton.styleFrom( + foregroundColor: Colors.blue, + side: const BorderSide(color: Colors.blue, width: 2), + padding: + const EdgeInsets.symmetric(horizontal: 20, vertical: 20), + ), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Image.asset('assets/google_logo.svg.png', width: 24), + const SizedBox(width: 8), + const Text('Sign in with Google', + style: TextStyle(fontWeight: FontWeight.w300)), + ], + ), + ), + const SizedBox(height: 20), + OutlinedButton( + onPressed: () async { + final user = await _authService.signInWithGitHub(); + if (user != null) { + print( + "Successfully signed in with GitHub: ${user.user?.displayName}"); + } + }, + style: OutlinedButton.styleFrom( + foregroundColor: Colors.black, + side: const BorderSide(color: Colors.black, width: 2), + padding: + const EdgeInsets.symmetric(horizontal: 20, vertical: 20), + ), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Image.asset('assets/github_logo.svg.png', width: 24), + const SizedBox(width: 8), + const Text('Sign in with GitHub', + style: TextStyle(fontWeight: FontWeight.w300)), + ], + ), + ), + ], + ), + ), + ); + } +}