Google Auth with PocketBase is failing to launch URL for auth process

Database & APIs

I have tried to implement Google auth with self hosted PB instance, but keep failing to see this through.

The latest issue I got to is failure to trigger auth window for Google authentication process.

Tried to use tabs as well with no luck.

Any advise appreciated!

What have you tried so far?

// Automatic FlutterFlow imports
import '/backend/schema/structs/index.dart';
import '/backend/supabase/supabase.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:flutter_custom_tabs/flutter_custom_tabs.dart';
import 'package:url_launcher/url_launcher.dart' as url_launcher; // ๐Ÿ‘ˆ Important
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:pocketbase/pocketbase.dart';

Future<dynamic> googlePocketBaseLogin() async {
  final pb = PocketBase('[PB_URL]');

  // โšก Step 1: Fetch OAuth2 login URL manually
  final authMethods = await pb.collection('users').listAuthMethods();

  // โœ… Here correctly parse the data
  final authProviders =
      authMethods.toJson()['authProviders'] as Map<String, dynamic>;

  final googleProvider = authProviders['google'] as Map<String, dynamic>;

  final authUrl = googleProvider['authUrl'] as String;

  // โšก Step 2: Launch the URL (Web vs Mobile)
  if (kIsWeb) {
    // ๐ŸŒ On Web: Open in same tab
    await url_launcher.launchUrl(
      Uri.parse(authUrl),
      mode: url_launcher.LaunchMode.platformDefault,
      webOnlyWindowName: '_self',
    );
  } else {
    // ๐Ÿ“ฑ On Mobile: Open in Custom Tab
    await launchUrl(
      Uri.parse(authUrl),
      customTabsOptions: CustomTabsOptions(
        colorSchemes: CustomTabsColorSchemes.defaults(
          toolbarColor: Color(0xFF000000),
        ),
        shareState: CustomTabsShareState.on,
        urlBarHidingEnabled: true,
        showTitle: true,
      ),
      safariVCOptions: SafariViewControllerOptions(
        preferredBarTintColor: Color(0xFF000000),
        preferredControlTintColor: Color(0xFFFFFFFF),
        barCollapsingEnabled: true,
      ),
    );
  }

  // โšก Step 3: Return empty values for now
  return {
    'authToken': '',
    'userId': '',
    'email': '',
  };
}
Did you check FlutterFlow's Documentation for this topic?
Yes
2