Skip to content
Back

Google OAuth2 Login Gets Stuck in Redirect Loop on Flutter

  • 0
  • Flutter
  • Auth
mobix
11 Sep, 2025, 11:43

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.

TypeScript
For use with requests from a web server
URIs 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/google
URIs 3 
https://cloud.appwrite.io/v1/account/sessions/oauth2/callback/google/[PROJECT_ID]

and in my code

TypeScript
 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.

TL;DR
Developers are facing a redirect loop issue with Google OAuth2 login on their Flutter app using the Appwrite SDK. After successful sign-in, the browser gets stuck in a loop instead of returning to the app. The issue seems to be related to the redirect URIs setup. The provided code snippet suggests that the OAuth session is successfully created, but the app still encounters the loop. Manually closing the browser allows the login process to complete. Solution: The redirect URIs in the Google Cloud console need to be set up correctly to avoid the loop. Double-check the URIs in the console and ensure they match the ones in the code
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more