> For the complete documentation index, see [llms.txt](/llms.txt).

# Sign in a user

To sign in a user, use the `connectTo` method. It triggers the sign-in flow and opens an in-app browser so the user can authenticate with the selected provider. Pass supported `AuthConnection` values for social logins (such as Google, Apple, Facebook) or custom JWT connections.

## Parameters

The `connectTo` method takes `LoginParams` as a required input.

**Table**

| Parameter                  | Description                                                                                                                                                                                                                                                                              |
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `authConnection`           | Sets the OAuth sign-in method to use. Supported values include `google`, `facebook`, `reddit`, `discord`, `twitch`, `github`, `apple`, `kakao`, `linkedin`, `twitter`, `weibo`, `wechat`, `line`, `email_passwordless`, `email_password`, `custom`, `sms_passwordless`, and `farcaster`. |
| `authConnectionId?`        | Auth connection ID from the Embedded Wallets dashboard. Required for `custom` connections.                                                                                                                                                                                               |
| `groupedAuthConnectionId?` | Grouped auth connection ID for aggregate connections.                                                                                                                                                                                                                                    |
| `extraLoginOptions?`       | OAuth options for the corresponding `authConnection`. For example, pass the user's email address as `login_hint` for `email_passwordless`. Defaults to `null`.                                                                                                                           |
| `appState?`                | Tracks app state when the user returns after sign-in. Defaults to `null`.                                                                                                                                                                                                                |
| `mfaLevel?`                | Customizes the MFA screen during OAuth authentication. Takes `MFALevel.OPTIONAL`, `MFALevel.MANDATORY`, or `MFALevel.NONE`. `MFALevel.DEFAULT` was removed in v8. See [MFA](/embedded-wallets/sdk/flutter/advanced/mfa/).                                                                |
| `dappShare?`               | Custom connection logins can return a dapp share after successful sign-in. Useful if your dapp uses this share to let users sign in without repeating the full flow.                                                                                                                     |
| `curve?`                   | Determines the public key encoded in the JWT returned by `getUserInfo`. Does not change the private key format from Web3Auth. `getPrivateKey` always returns secp256k1. Use `getEd25519PrivateKey` for ed25519. Defaults to `Curve.secp256k1`.                                           |
| `idToken?`                 | JWT (ID token) for `custom` connections. Pass Firebase, Auth0, or other provider tokens here instead of `extraLoginOptions.id_token`.                                                                                                                                                    |
| `loginHint?`               | Optional login hint (for example, email or phone number) passed directly on `LoginParams`.                                                                                                                                                                                               |
| `recordId?`                | Optional audit record ID sent with the sign-in request. When `null`, the native SDK generates a UUID.                                                                                                                                                                                    |
| `loginSource?`             | Audit login source sent with the sign-in request. Defaults to `web3auth-flutter`. You don't need to set this.                                                                                                                                                                            |

**Class**

```dart
class LoginParams {
  final AuthConnection authConnection;
  final String? authConnectionId;
  final String? groupedAuthConnectionId;
  final String? appState;
  final MFALevel? mfaLevel;
  final ExtraLoginOptions? extraLoginOptions;
  final String? dappShare;
  final Curve? curve;
  final String? dappUrl;
  String? loginHint;
  final String? idToken;
  final String? recordId;
  final String? loginSource;

  LoginParams({
    required this.authConnection,
    this.authConnectionId,
    this.groupedAuthConnectionId,
    this.appState,
    this.mfaLevel,
    this.extraLoginOptions,
    this.dappShare,
    this.curve = Curve.secp256k1,
    this.dappUrl,
    this.loginHint,
    this.idToken,
    this.recordId,
    this.loginSource,
  });
}

enum AuthConnection {
  google,
  facebook,
  reddit,
  discord,
  twitch,
  github,
  apple,
  kakao,
  linkedin,
  twitter,
  weibo,
  wechat,
  line,
  email_passwordless,
  email_password,
  custom,
  sms_passwordless,
  farcaster,
}

```

## Usage

```dart
final Web3AuthResponse response = await Web3AuthFlutter.connectTo(
  LoginParams(authConnection: AuthConnection.google),
);

```

## Response

`connectTo` returns a `Web3AuthResponse`. You can also read the current response later with [getWeb3AuthResponse](/embedded-wallets/sdk/flutter/usage/get-web3auth-response/).

| Name                     | Description                                                                                              |
| ------------------------ | -------------------------------------------------------------------------------------------------------- |
| `privateKey?`            | secp256k1 private key, compatible with EVM chains.                                                       |
| `ed25519PrivateKey?`     | ed25519 private key, compatible with Solana and other ed25519 chains.                                    |
| `userInfo?`              | The signed-in user's information. See [getUserInfo](/embedded-wallets/sdk/flutter/usage/get-user-info/). |
| `sessionId?`             | Current session ID.                                                                                      |
| `coreKitKey?`            | secp256k1 SFA key, returned when `useSFAKey` is `true` in `Web3AuthOptions`.                             |
| `coreKitEd25519PrivKey?` | ed25519 SFA key, returned when `useSFAKey` is `true` in `Web3AuthOptions`.                               |
| `factorKey?`             | Factor key, if available.                                                                                |
| `signatures?`            | Session signatures as a `List<String>`.                                                                  |
| `tssShareIndex?`         | TSS share index.                                                                                         |
| `tssPubKey?`             | TSS public key.                                                                                          |
| `tssShare?`              | TSS share.                                                                                               |
| `tssTag?`                | TSS tag.                                                                                                 |
| `tssNonce?`              | TSS nonce.                                                                                               |
| `nodeIndexes?`           | Node indexes as a `List<int>`.                                                                           |
| `keyMode?`               | Key mode of the account.                                                                                 |
| `error?`                 | Error message, if any.                                                                                   |

## Handle errors

Error handling differs by platform in v8:

- **Android:** every `connectTo` failure, including a closed sign-in tab, throws `UserCancelledException`. Call `Web3AuthFlutter.setCustomTabsClosed()` when the app resumes so the SDK can detect a closed custom tab. See [Handle custom tabs](/embedded-wallets/sdk/flutter/#handle-custom-tabs).
- **iOS:** failures, including cancellation, throw a `PlatformException` with the code `LoginFailedException`.

```dart
import 'dart:developer';

import 'package:flutter/services.dart';

try {
  final response = await Web3AuthFlutter.connectTo(
    LoginParams(authConnection: AuthConnection.google),
  );
} on UserCancelledException {
  // Android: sign-in was cancelled or failed.
  log("Sign-in cancelled or failed.");
} on PlatformException catch (e) {
  // iOS: e.code is "LoginFailedException".
  log("Sign-in failed: ${e.code} ${e.message}");
}

```

## Examples

**Google**

Usage

```dart
Future<void> initWeb3Auth() async {
  late final String redirectUrl;

  if (Platform.isAndroid) {
    redirectUrl = 'w3a://com.example.w3aflutter';
  } else if (Platform.isIOS) {
    redirectUrl = 'com.example.w3aflutter://auth';
  } else {
    throw UnKnownException('Unknown platform');
  }

  await Web3AuthFlutter.init(Web3AuthOptions(
    clientId: "WEB3AUTH_CLIENT_ID",
    web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet,
    redirectUrl: redirectUrl,
  ));

  try {
    await Web3AuthFlutter.initialize();
  } catch (e) {
    // No active session
  }
}

// Sign in
final Web3AuthResponse response = await Web3AuthFlutter.connectTo(
  LoginParams(authConnection: AuthConnection.google),
);

```

**Facebook**

Usage

```dart
final Web3AuthResponse response = await Web3AuthFlutter.connectTo(
  LoginParams(authConnection: AuthConnection.facebook),
);

```

**Discord**

Usage

```dart
final Web3AuthResponse response = await Web3AuthFlutter.connectTo(
  LoginParams(authConnection: AuthConnection.discord),
);

```

**Twitch**

Usage

```dart
final Web3AuthResponse response = await Web3AuthFlutter.connectTo(
  LoginParams(authConnection: AuthConnection.twitch),
);

```

**Email Passwordless**

Usage

```dart
final Web3AuthResponse response = await Web3AuthFlutter.connectTo(
  LoginParams(
    authConnection: AuthConnection.email_passwordless,
    extraLoginOptions: ExtraLoginOptions(login_hint: "hello@web3auth.io"),
  ),
);

```

**SMS Passwordless**

Usage

```dart
final Web3AuthResponse response = await Web3AuthFlutter.connectTo(
  LoginParams(
    authConnection: AuthConnection.sms_passwordless,
    extraLoginOptions: ExtraLoginOptions(login_hint: "+91-9911223344"),
  ),
);

```

**Farcaster**

Usage

```dart
final Web3AuthResponse response = await Web3AuthFlutter.connectTo(
  LoginParams(authConnection: AuthConnection.farcaster),
);

```

**Custom JWT**

Usage

```dart
final Web3AuthResponse response = await Web3AuthFlutter.connectTo(
  LoginParams(
    authConnection: AuthConnection.custom,
    authConnectionId: "YOUR_AUTH_CONNECTION_ID",
    idToken: "YOUR_JWT_TOKEN",
  ),
);

```
