Implementing social login with Para in Flutter applications
Para supports social login authentication in Flutter applications, allowing users to sign in using popular providers like Google, Apple, Twitter, Discord, and Facebook. This guide explains how to implement social login in your Flutter app using Para’s Flutter SDK v2.
The social login flow in mobile applications requires handling browser sessions and deeplinks to redirect users back to your app after successful authentication. Para’s v2 API provides a streamlined flow that automatically handles both new and existing users.
Farcaster authentication follows a unique flow in V2:
Copy
Ask AI
Future<void> authenticateWithFarcaster() async { // Step 1: Get the Farcaster connect URI final connectUri = await para.getFarcasterConnectUri().future; // Step 2: Launch the URI (opens Farcaster app/website for user authorization) if (await canLaunchUrl(Uri.parse(connectUri))) { await launchUrl(Uri.parse(connectUri)); } // Step 3: Poll for verification result final authState = await para.verifyFarcaster().future; // Step 4: Handle the authentication state switch (authState.stage) { case AuthStage.login: // Existing user - open passkey URL and wait for login if (authState.passkeyUrl != null) { final webAuthSession = FlutterWebAuthSession( callbackUrlScheme: 'yourapp', ); await launchUrl(Uri.parse(authState.passkeyUrl!)); // Wait for login to complete final loginResult = await para.waitForLogin().future; print('Farcaster user logged in'); } break; case AuthStage.signup: // New user - create wallet if (authState.passkeyUrl != null) { final webAuthSession = FlutterWebAuthSession( callbackUrlScheme: 'yourapp', ); await launchUrl(Uri.parse(authState.passkeyUrl!)); // Wait for wallet creation final walletResult = await para.waitForWalletCreation().future; print('New Farcaster wallet created'); } break; case AuthStage.verify: // Should not occur for Farcaster print('Unexpected verify stage for Farcaster'); break; }}
Check if a user is already authenticated when your app starts:
Copy
Ask AI
Future<void> checkAuthStatus() async { final isActive = await para.isSessionActive(); if (isActive) { // User is logged in final authDetails = await para.getCurrentUserAuthDetails(); final wallets = await para.fetchWallets(); print('User is logged in with ${wallets.length} wallets'); // Navigate to main app Navigator.pushReplacementNamed(context, '/home'); } else { // Show login screen Navigator.pushReplacementNamed(context, '/login'); }}
Social login with Para still requires creating a native passkey to secure the user’s wallets. After social authentication completes, Para associates a native passkey with the user’s account. For returning users, the native passkey is used for authentication. The passkey is associated on a per-app basis, making authentication streamlined.