> 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 navigates the user to a browser modal for authentication. Pass supported auth connections for specific social sign-ins (such as `.GOOGLE`, `.APPLE`, `.FACEBOOK`) or use whitelabel sign-in.

For SFA (Single Factor Auth) sign-in with a JWT token, pass the `idToken` parameter to authenticate directly without the browser modal.

## Parameters

The `connectTo` method accepts `LoginParams` as a required parameter and returns a `Web3AuthResponse`. After a successful sign-in, the same response is available in `web3Auth.web3AuthResponse`.

**Table**

| Parameter                  | Description                                                                                                                                                                                                                                                                                                    |
| -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `authConnection`           | It sets the OAuth sign-in method to be used. You can use any of the supported values: `.GOOGLE`, `.FACEBOOK`, `.REDDIT`, `.DISCORD`, `.TWITCH`, `.APPLE`, `.LINE`, `.GITHUB`, `.KAKAO`, `.LINKEDIN`, `.TWITTER`, `.WEIBO`, `.WECHAT`, `.EMAIL_PASSWORDLESS`, `.SMS_PASSWORDLESS`, `.FARCASTER`, and `.CUSTOM`. |
| `authConnectionId?`        | The auth connection ID for the connection. Required for SFA mode when `idToken` is passed. Default value is `nil`.                                                                                                                                                                                             |
| `groupedAuthConnectionId?` | The grouped auth connection ID for grouped auth connections. It accepts `String` as a value.                                                                                                                                                                                                                   |
| `appState?`                | It can be used to keep track of the app state when user will be redirected to app after sign-in. Default is `nil`, and it accepts a string value.                                                                                                                                                              |
| `mfaLevel?`                | Customize the MFA screen shown to the user during authentication. Accepts `.OPTIONAL`, `.MANDATORY`, or `.NONE`. Default value is `nil`, which uses the default behavior of the authentication service. See [MFA](/embedded-wallets/sdk/ios/advanced/mfa/).                                                    |
| `extraLoginOptions?`       | It can be used to set the OAuth sign-in options for the corresponding `authConnection`. Default value is `nil`, and it accepts `ExtraLoginOptions` as a value.                                                                                                                                                 |
| `dappShare?`               | Custom auth connection sign-ins can get a dapp share returned to them post successful sign-in. This is useful if the dapps want to use this share to allow users to sign in seamlessly. It accepts a string value.                                                                                             |
| `curve?`                   | It will be used to determine the public key encoded in the JWT token which is returned in `getUserInfo` after user sign-in. Private key returned by `getPrivateKey` is always secp256k1. To get the ed25519 key you can use `getEd25519PrivateKey`. The default value is `.SECP256K1`.                         |
| `dappUrl?`                 | URL of your dapp. It accepts a string value.                                                                                                                                                                                                                                                                   |
| `loginHint?`               | Used to specify the user's email address or phone number for email/SMS passwordless sign-in flows. For SMS, the format should be: `+{country_code}-{phone_number}` (for example `+1-1234567890`). It accepts a string value.                                                                                   |
| `idToken?`                 | JWT token for SFA (Single Factor Auth) mode. When provided, enables direct authentication without the social sign-in browser flow. It accepts a string value.                                                                                                                                                  |
| `recordId?`                | Identifier for this sign-in attempt. If `nil`, the SDK generates a UUID. It accepts a string value.                                                                                                                                                                                                            |
| `loginSource?`             | Identifies the source of the sign-in request. If `nil`, the SDK uses `web3auth-ios`. It accepts a string value.                                                                                                                                                                                                |

note

Pass `LoginParams` arguments in the order shown in the **Struct** tab. Swift rejects labeled arguments that are out of declaration order.

**Struct**

```swift
public struct LoginParams: Codable, Sendable {
    public init(
        authConnection: AuthConnection,
        authConnectionId: String? = nil,
        groupedAuthConnectionId: String? = nil,
        appState: String? = nil,
        mfaLevel: MFALevel? = nil,
        extraLoginOptions: ExtraLoginOptions? = nil,
        dappShare: String? = nil,
        curve: SUPPORTED_KEY_CURVES = .SECP256K1,
        dappUrl: String? = nil,
        loginHint: String? = nil,
        idToken: String? = nil,
        recordId: String? = nil,
        loginSource: String? = nil
    )
}

public enum AuthConnection: String, Codable {
    case GOOGLE = "google"
    case FACEBOOK = "facebook"
    case REDDIT = "reddit"
    case DISCORD = "discord"
    case TWITCH = "twitch"
    case APPLE = "apple"
    case LINE = "line"
    case GITHUB = "github"
    case KAKAO = "kakao"
    case LINKEDIN = "linkedin"
    case TWITTER = "twitter"
    case WEIBO = "weibo"
    case WECHAT = "wechat"
    case EMAIL_PASSWORDLESS = "email_passwordless"
    case CUSTOM = "custom"
    case SMS_PASSWORDLESS = "sms_passwordless"
    case FARCASTER = "farcaster"
}

```

## Usage

```swift
import Web3Auth

let web3Auth = try await Web3Auth(
    options: Web3AuthOptions(
        clientId: "YOUR_WEB3AUTH_CLIENT_ID",
        redirectUrl: "com.yourapp.bundleid://auth",
        web3AuthNetwork: .SAPPHIRE_MAINNET
    )
)

let result = try await web3Auth.connectTo(loginParams: LoginParams(authConnection: .GOOGLE))

```

## Examples

**Google**

```swift
import Web3Auth

let web3Auth = try await Web3Auth(
    options: Web3AuthOptions(
        clientId: "YOUR_WEB3AUTH_CLIENT_ID",
        redirectUrl: "com.yourapp.bundleid://auth",
        web3AuthNetwork: .SAPPHIRE_MAINNET
    )
)

let result = try await web3Auth.connectTo(loginParams: LoginParams(authConnection: .GOOGLE))

```

**Facebook**

```swift
import Web3Auth

let web3Auth = try await Web3Auth(
    options: Web3AuthOptions(
        clientId: "YOUR_WEB3AUTH_CLIENT_ID",
        redirectUrl: "com.yourapp.bundleid://auth",
        web3AuthNetwork: .SAPPHIRE_MAINNET
    )
)

let result = try await web3Auth.connectTo(loginParams: LoginParams(authConnection: .FACEBOOK))

```

**Discord**

```swift
import Web3Auth

let web3Auth = try await Web3Auth(
    options: Web3AuthOptions(
        clientId: "YOUR_WEB3AUTH_CLIENT_ID",
        redirectUrl: "com.yourapp.bundleid://auth",
        web3AuthNetwork: .SAPPHIRE_MAINNET
    )
)

let result = try await web3Auth.connectTo(loginParams: LoginParams(authConnection: .DISCORD))

```

**Twitch**

```swift
import Web3Auth

let web3Auth = try await Web3Auth(
    options: Web3AuthOptions(
        clientId: "YOUR_WEB3AUTH_CLIENT_ID",
        redirectUrl: "com.yourapp.bundleid://auth",
        web3AuthNetwork: .SAPPHIRE_MAINNET
    )
)

let result = try await web3Auth.connectTo(loginParams: LoginParams(authConnection: .TWITCH))

```

**Email Passwordless**

note

SDK v13.0.0 always uses the one-time code (OTP) flow for email passwordless sign-in. The `ExtraLoginOptions` initializer ignores the `flow_type` argument, so passing `.link` has no effect.

```swift
import Web3Auth

let web3Auth = try await Web3Auth(
    options: Web3AuthOptions(
        clientId: "YOUR_WEB3AUTH_CLIENT_ID",
        redirectUrl: "com.yourapp.bundleid://auth",
        web3AuthNetwork: .SAPPHIRE_MAINNET
    )
)

let result = try await web3Auth.connectTo(
    loginParams: LoginParams(
        authConnection: .EMAIL_PASSWORDLESS,
        loginHint: "hello@web3auth.io"
    )
)

```

**SMS Passwordless**

```swift
import Web3Auth

let web3Auth = try await Web3Auth(
    options: Web3AuthOptions(
        clientId: "YOUR_WEB3AUTH_CLIENT_ID",
        redirectUrl: "com.yourapp.bundleid://auth",
        web3AuthNetwork: .SAPPHIRE_MAINNET
    )
)

let result = try await web3Auth.connectTo(
    loginParams: LoginParams(
        authConnection: .SMS_PASSWORDLESS,
        // The phone number should be in format of +{country_code}-{phone_number}
        loginHint: "+91-9911223344"
    )
)

```

**Farcaster**

```swift
import Web3Auth

let web3Auth = try await Web3Auth(
    options: Web3AuthOptions(
        clientId: "YOUR_WEB3AUTH_CLIENT_ID",
        redirectUrl: "com.yourapp.bundleid://auth",
        web3AuthNetwork: .SAPPHIRE_MAINNET
    )
)

let result = try await web3Auth.connectTo(loginParams: LoginParams(authConnection: .FARCASTER))

```

**SFA JWT**

For SFA (Single Factor Auth) mode, pass the JWT token via `idToken` to authenticate directly without any browser-based sign-in flow. This is useful when you already have a JWT from your own authentication system.

```swift
import Web3Auth

let web3Auth = try await Web3Auth(
    options: Web3AuthOptions(
        clientId: "YOUR_WEB3AUTH_CLIENT_ID",
        redirectUrl: "com.yourapp.bundleid://auth",
        web3AuthNetwork: .SAPPHIRE_MAINNET
    )
)

let result = try await web3Auth.connectTo(
    loginParams: LoginParams(
        authConnection: .CUSTOM,
        authConnectionId: "your-auth-connection-id", // Get it from the Embedded Wallets dashboard
        idToken: "your_jwt_token"
    )
)

```

If the auth connection belongs to a grouped auth connection, also pass `groupedAuthConnectionId`. The SDK then signs in with the grouped connection and uses `authConnectionId` as the sub-connection:

```swift
let result = try await web3Auth.connectTo(
    loginParams: LoginParams(
        authConnection: .CUSTOM,
        authConnectionId: "your-auth-connection-id",
        groupedAuthConnectionId: "your-grouped-auth-connection-id",
        idToken: "your_jwt_token"
    )
)

```

Users who sign in with SFA can't call `enableMFA` or `manageMFA`.
