Back

google auth problems

  • 0
  • Flutter
  • Web
  • Cloud
OppositeDragon
16 Jan, 2024, 21:33

I have been having this issue for quite a while. This functionality was working fine on all flutter platforms, but then suddenly stopped working.

TL;DR
Title: Google Auth Problems Developers have encountered issues with Google authentication in their Flutter app across multiple platforms. The functionality was previously working but stopped abruptly. Solution: 1. In the `auth.html` file, ensure that authentication is completed and closed properly. The JavaScript code should send a post message to the Flutter app and close the window. 2. In the `androidManifest.xml` file, make sure the activity for the CallbackActivity has the correct data scheme specified according to your Flutter app's package name. 3. Check the Dart code for implementing Google sign-in. Make sure the necessary client and account configurations are set and the
OppositeDragon
16 Jan, 2024, 21:35
OppositeDragon
16 Jan, 2024, 21:35

on flutter android

OppositeDragon
16 Jan, 2024, 21:36

on flutter web

OppositeDragon
16 Jan, 2024, 21:39
TypeScript
Client client(ClientRef ref) {
  return Client().setEndpoint('https://cloud.appwrite.io/v1').setProject('linearprogrammingapp');
}

Account account(AccountRef ref) {
  final client = ref.watch(clientProvider);
  return Account(client);
}

Future<void> signInWithGoogle() async {
    final account = ref.read(accountProvider);
    final result = await account.createOAuth2Session(
      provider: 'google',
      success: _successCallback(),
      failure: _failureCallback(),
    );
    debugPrint('google siginresult: $result');
  }

String? _successCallback() {
    if (kIsWeb) {
      final Uri? location = href == null ? null : Uri.parse(href!);
      return '${location?.origin}/auth.html';
    }
    switch (defaultTargetPlatform) {
      case TargetPlatform.android:
        return null;
      case TargetPlatform.fuchsia:
        return null;
      case TargetPlatform.iOS:
        return null;
      case TargetPlatform.macOS:
        return null;
      case TargetPlatform.linux || TargetPlatform.windows:
        return 'http://localhost:1001/auth/oauth2/success';
      default:
        throw UnsupportedError('Unsupported platform');
    }
  }

  String? _failureCallback() {
    switch (defaultTargetPlatform) {
      default:
        return '';
    }
  }
OppositeDragon
16 Jan, 2024, 21:42

for androidManifest

TypeScript
<activity android:name="io.appwrite.views.CallbackActivity" android:exported="true">
      <intent-filter android:label="android_web_auth">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="appwrite-callback-linearprogrammingapp" />
      </intent-filter>
    </activity> 
OppositeDragon
16 Jan, 2024, 21:43

auth.html

TypeScript
<!DOCTYPE html>
<title>Authentication complete</title>
<p>Authentication is complete. If this does not happen automatically, please
  close the window.</p>
<script>
  window.opener.postMessage({
    'flutter-web-auth-2': window.location.href
  }, window.location.origin);
  window.close();
</script>
OppositeDragon
16 Jan, 2024, 21:45

I would appreciate any help, on solving this. Thank you.

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