Flutter Developer
I'm facing an issue with the Google OAuth2 login flow on my Flutter Android app using the Appwrite SDK. After a successful sign-in with Google, the browser enters a redirect loop instead of returning to my app. The login flow previously worked as expected, but has recently started failing.
For use with requests from a web serverURIs 1 https://fra.cloud.appwrite.io/v1/account/sessions/oauth2/callback/google/[PROJECT_ID]URIs 2 https://cloud.appwrite.io/v1/account/sessions/oauth2/callback/googleURIs 3 https://cloud.appwrite.io/v1/account/sessions/oauth2/callback/google/[PROJECT_ID]and in my code
Future<void> signInWithOAuth(OAuthProvider provider) async {
try {
print("🔑 Starting OAuth sign-in with provider: $provider");
// ✅ Check existing session
try {
final currentUser = await _account.get();
print("⚠️ User already logged in. Logging out first...");
await signOut();
} catch (_) {
// no active session, safe to continue
}
await _account.createOAuth2Session(provider: provider);
print("✅ OAuth session created successfully. Checking auth status...");
await checkAuthStatus();
} on AppwriteException catch (e) {
print("❌ AppwriteException during OAuth: ${e.message}, code: ${e.code}");
if (e.response != null) {
print("📡 Full error response: ${e.response}");
}
Get.snackbar('Error', e.message ?? 'OAuth sign-in failed');
} catch (e) {
print("⚠️ Unexpected error during OAuth: $e");
Get.snackbar('Error', 'An unexpected error occurred.');
}
}
Now when i press login button in my app it opens a browser with google login page. then i select my account and it loads and i see the appwrite loading page and then back to google login page inside the browser. meanwhile my terminal
OAuth session created successfully. Checking auth status... and if i manually close the browser i'm logged in.