Google Oath2 for Flutter Android App not redirecting back to the app after successful authentication
- 0
- Android
- Flutter
- Auth
I have this function in my auth file for logging in via google Future<void> loginWithGoogle() async { try { final result = await FlutterWebAuth2.authenticate( url: 'https://fra.cloud.appwrite.io/v1/account/sessions/oauth2/google?project=685d2b28003a614fa813', callbackUrlScheme: 'com.example.xhale', );
final uri = Uri.parse(result);
final sessionId =
uri.fragment
.split('&')
.firstWhere((e) => e.startsWith('sessionId='))
.split('=')[1];
await widget.account.updateSession(sessionId: sessionId);
final user = await widget.account.get();
final userId = user.$id;
final email = user.email;
final name = user.name;
final userNotifier = ref.read(userProvider.notifier);
final exists = await userNotifier.checkIfUserExists(userId);
if (exists) {
await userNotifier.fetchUserData(userId);
if (!mounted) return;
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (_) => HomePage(account: widget.account)),
);
} else {
await userNotifier.createNewUser(
userId: userId,
email: email,
name: name,
phoneNumber: null,
);
if (!mounted) return;
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder:
(_) => InitialSmokingPreferencesPage(
account: widget.account,
email: email,
name: name,
phoneNumber: null,
),
),
);
}
} catch (e) {
debugPrint('❌ Google login error: $e')
}
}
The AndroidManifest file and the google cloud client are configured, but after I pick the account, i stay stuck at the 'https://fra.cloud.appwrite.io/v1/console/auth/oath2/success?project=685d2b28003a614fa813' and not redirected to my app. Why?
I will add the relevant AndroidManifest.xml code here for reference: <activity android:name=".MainActivity" android:enableOnBackInvokedCallback="true" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> <!-- Specifies an Android theme to apply to this Activity as soon as the Android process has started. This theme is visible to the user while the Flutter UI initializes. After that, this theme continues to determine the Window background behind the Flutter UI. --> <meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" /> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <!-- CallbackActivity για Google Sign-In -->
<!-- Add this inside the <application> tag, along side the existing <activity> tags --> <activity android:exported="true"
android:name="com.linusu.flutter_web_auth_2.CallbackActivity">
<intent-filter android:label="flutter_web_auth_2">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="com.example.xhale" android:host="callback" />
</intent-filter>
</activity>
What is the scheme you are using?
Recommended threads
- Realtime: Listener not triggered on upda...
I self host appwrite 1.8.1. The genereal functionallity works fine. But my realtime subscription isn't updating. I see "Received heartbeat response from realtim...
- My account got banned without obvious re...
Hello, I’m a normal user of Appwrite. Today I found my account was banned suddenly, and I can’t log in normally. I have only been doing normal development and...
- general_route_not_found - Auth Guide
If you’ve just added a subdomain to your project, verified your DNS records, and confirmed your SSL certificate is working, but you're still hitting a `general_...