aboutsummaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authorGravatar hunteraraujo <hunter_araujo@msn.com> 2023-10-05 23:50:21 -0700
committerGravatar hunteraraujo <hunter_araujo@msn.com> 2023-10-05 23:50:21 -0700
commitbc10845cb504b7b9c47c25962e0428a9b098d6df (patch)
tree8531355b5cd1a5e540e26ecb416682e0a13e638b /frontend
parentUpdate frontend build (#5569) (diff)
downloadAuto-GPT-bc10845cb504b7b9c47c25962e0428a9b098d6df.tar.gz
Auto-GPT-bc10845cb504b7b9c47c25962e0428a9b098d6df.tar.bz2
Auto-GPT-bc10845cb504b7b9c47c25962e0428a9b098d6df.zip
Include pop ups + change auth flow for github codespace
Diffstat (limited to 'frontend')
-rw-r--r--frontend/lib/main.dart5
-rw-r--r--frontend/lib/services/auth_service.dart54
2 files changed, 17 insertions, 42 deletions
diff --git a/frontend/lib/main.dart b/frontend/lib/main.dart
index 160022215..76b0564c4 100644
--- a/frontend/lib/main.dart
+++ b/frontend/lib/main.dart
@@ -84,7 +84,10 @@ class MyApp extends StatelessWidget {
if (snapshot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator();
}
- if (snapshot.hasData && snapshot.data != null) {
+ String hostname = Uri.base.host;
+
+ if (snapshot.hasData && snapshot.data != null ||
+ hostname.contains('github.dev')) {
return MultiProvider(
providers: [
ChangeNotifierProvider(
diff --git a/frontend/lib/services/auth_service.dart b/frontend/lib/services/auth_service.dart
index 734b0661c..2a3693638 100644
--- a/frontend/lib/services/auth_service.dart
+++ b/frontend/lib/services/auth_service.dart
@@ -8,30 +8,20 @@ class AuthService {
"387936576242-iejdacrjljds7hf99q0p6eqna8rju3sb.apps.googleusercontent.com");
// Sign in with Google using redirect
+// Sign in with Google using redirect
Future<UserCredential?> signInWithGoogle() async {
try {
- final GoogleAuthProvider googleProvider = GoogleAuthProvider();
-
- // Step 1: Detect the current hostname
- String hostname = Uri.base.host;
-
- // Step 2: Determine the redirect URI
- String redirectUri;
- if (hostname.contains('github.dev')) {
- // If running in Github Codespaces
- redirectUri = Uri.base.toString();
- } else {
- // For local development or other environments, set accordingly
- redirectUri = 'http://localhost:8000'; // Example for local development
+ final GoogleSignInAccount? googleSignInAccount =
+ await googleSignIn.signIn();
+ if (googleSignInAccount != null) {
+ final GoogleSignInAuthentication googleSignInAuthentication =
+ await googleSignInAccount.authentication;
+ final AuthCredential credential = GoogleAuthProvider.credential(
+ accessToken: googleSignInAuthentication.accessToken,
+ idToken: googleSignInAuthentication.idToken,
+ );
+ return await _auth.signInWithCredential(credential);
}
-
- // Step 3: Update OAuth 2.0 provider configuration dynamically
- googleProvider.setCustomParameters({'redirect_uri': redirectUri});
-
- await _auth.signInWithRedirect(googleProvider);
- final result = await _auth.getRedirectResult();
- print(result);
- return result;
} catch (e) {
print("Error during Google Sign-In: $e");
return null;
@@ -41,26 +31,8 @@ class AuthService {
// Sign in with GitHub using redirect
Future<UserCredential?> signInWithGitHub() async {
try {
- final GithubAuthProvider githubProvider = GithubAuthProvider();
-
- // Step 1: Detect the current hostname
- String hostname = Uri.base.host;
-
- // Step 2: Determine the redirect URI
- String redirectUri;
- if (hostname.contains('github.dev')) {
- // If running in Github Codespaces
- redirectUri = Uri.base.toString();
- } else {
- // For local development or other environments, set accordingly
- redirectUri = 'http://localhost:8000'; // Example for local development
- }
-
- // Step 3: Update OAuth 2.0 provider configuration dynamically
- githubProvider.setCustomParameters({'redirect_uri': redirectUri});
-
- await _auth.signInWithRedirect(githubProvider);
- return await _auth.getRedirectResult();
+ final GithubAuthProvider provider = GithubAuthProvider();
+ return await _auth.signInWithPopup(provider);
} catch (e) {
print("Error during GitHub Sign-In: $e");
return null;