mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 06:24:20 +01:00
Integrate Firebase Authentication and Streamline Auth Flow in main.dart
This commit integrates Firebase Authentication into the application and refactors the `main.dart` file to streamline the user authentication flow. The application will now automatically switch between the main layout and the authentication UI based on the user's sign-in status. - Added Firebase initialization to the `main()` function for Firebase Authentication. - Replaced the home page in `MyApp` with a `StreamBuilder` that listens for Firebase auth state changes. - Based on the auth state, the home page will either show `MainLayout` (if the user is signed in) or `FirebaseAuthView` (if the user is not signed in). - Added necessary imports for the Firebase and authentication services.
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
|
import 'package:auto_gpt_flutter_client/services/auth_service.dart';
|
||||||
|
import 'package:auto_gpt_flutter_client/views/auth/firebase_auth_view.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'views/main_layout.dart';
|
import 'views/main_layout.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
|
|
||||||
import 'package:auto_gpt_flutter_client/viewmodels/task_viewmodel.dart';
|
import 'package:auto_gpt_flutter_client/viewmodels/task_viewmodel.dart';
|
||||||
import 'package:auto_gpt_flutter_client/viewmodels/chat_viewmodel.dart';
|
import 'package:auto_gpt_flutter_client/viewmodels/chat_viewmodel.dart';
|
||||||
@@ -14,7 +18,20 @@ import 'package:auto_gpt_flutter_client/services/benchmark_service.dart';
|
|||||||
import 'package:auto_gpt_flutter_client/utils/rest_api_utility.dart';
|
import 'package:auto_gpt_flutter_client/utils/rest_api_utility.dart';
|
||||||
|
|
||||||
// TODO: Update documentation throughout project for consistency
|
// TODO: Update documentation throughout project for consistency
|
||||||
void main() {
|
void main() async {
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
await Firebase.initializeApp(
|
||||||
|
options: const FirebaseOptions(
|
||||||
|
apiKey: 'AIzaSyBvYLAK_A0uhFuVPQbTxUdVWbb_Lsur9cg',
|
||||||
|
authDomain: 'prod-auto-gpt.firebaseapp.com',
|
||||||
|
projectId: 'prod-auto-gpt',
|
||||||
|
storageBucket: 'prod-auto-gpt.appspot.com',
|
||||||
|
messagingSenderId: '387936576242',
|
||||||
|
appId: '1:387936576242:web:7536e0c50dd81b4dd7a66b',
|
||||||
|
measurementId: 'G-8PRS69JJRL',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
runApp(
|
runApp(
|
||||||
MultiProvider(
|
MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
@@ -48,29 +65,36 @@ void main() {
|
|||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Fetch services from providers
|
|
||||||
final chatService = Provider.of<ChatService>(context, listen: false);
|
|
||||||
final taskService = Provider.of<TaskService>(context, listen: false);
|
|
||||||
final benchmarkService =
|
|
||||||
Provider.of<BenchmarkService>(context, listen: false);
|
|
||||||
taskService.loadDeletedTasks();
|
|
||||||
|
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'AutoGPT Flutter Client',
|
title: 'AutoGPT Flutter Client',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
primarySwatch: Colors.blue,
|
primarySwatch: Colors.blue,
|
||||||
),
|
),
|
||||||
home: MultiProvider(
|
home: StreamBuilder<User?>(
|
||||||
providers: [
|
stream: FirebaseAuth.instance.authStateChanges(),
|
||||||
ChangeNotifierProvider(
|
builder: (context, snapshot) {
|
||||||
create: (context) => ChatViewModel(chatService)),
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
ChangeNotifierProvider(
|
return CircularProgressIndicator();
|
||||||
create: (context) => TaskViewModel(taskService)),
|
}
|
||||||
ChangeNotifierProvider(
|
if (snapshot.hasData && snapshot.data != null) {
|
||||||
create: (context) => SkillTreeViewModel(benchmarkService),
|
return MultiProvider(
|
||||||
),
|
providers: [
|
||||||
],
|
ChangeNotifierProvider(
|
||||||
child: MainLayout(),
|
create: (context) => ChatViewModel(
|
||||||
|
Provider.of<ChatService>(context, listen: false))),
|
||||||
|
ChangeNotifierProvider(
|
||||||
|
create: (context) => TaskViewModel(
|
||||||
|
Provider.of<TaskService>(context, listen: false))),
|
||||||
|
ChangeNotifierProvider(
|
||||||
|
create: (context) => SkillTreeViewModel(
|
||||||
|
Provider.of<BenchmarkService>(context, listen: false)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
child: MainLayout(),
|
||||||
|
); // User is signed in
|
||||||
|
}
|
||||||
|
return FirebaseAuthView(); // User is not signed in, show auth UI
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user