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
- Roles Enum Limitation in Kotlin SDK
The createMembership method in the Appwrite Kotlin SDK now requires List<io.appwrite.enums.Roles> instead of List<String>, but the predefined Roles enum only co...
- Server Down
Appwrite services are down. When will they start working again?
- Need help to create a wrapper which let ...
I’m looking for help setting up Appwrite properly on a VPS so I can build a self-hosting wrapper around it. The goal is to provide a Linux executable that allow...