> 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.

**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`, and `.FARCASTER`. |
| `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.                                                                                                                                                                                                        |
| `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.                                                                                                                                      |
| `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. Default value is `.DEFAULT`, which shows MFA screen every 3rd sign-in. It accepts `MFALevel` 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`.              |
| `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.                                                                                                                                       |

**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
    )
}

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",
        web3AuthNetwork: .SAPPHIRE_MAINNET,
        redirectUrl: "com.yourapp.bundleid://auth"
    )
)

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",
        web3AuthNetwork: .SAPPHIRE_MAINNET,
        redirectUrl: "com.yourapp.bundleid://auth"
    )
)

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",
        web3AuthNetwork: .SAPPHIRE_MAINNET,
        redirectUrl: "com.yourapp.bundleid://auth"
    )
)

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",
        web3AuthNetwork: .SAPPHIRE_MAINNET,
        redirectUrl: "com.yourapp.bundleid://auth"
    )
)

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",
        web3AuthNetwork: .SAPPHIRE_MAINNET,
        redirectUrl: "com.yourapp.bundleid://auth"
    )
)

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

```

**Email Passwordless**

```swift
import Web3Auth

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

let result = try await web3Auth.connectTo(
    loginParams: LoginParams(
        authConnection: .EMAIL_PASSWORDLESS,
        loginHint: "hello@web3auth.io",
        extraLoginOptions: ExtraLoginOptions(
            flow_type: .code // Use .code for OTP flow or .link for magic link flow
        )
    )
)

```

**SMS Passwordless**

```swift
import Web3Auth

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

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",
        web3AuthNetwork: .SAPPHIRE_MAINNET,
        redirectUrl: "com.yourapp.bundleid://auth"
    )
)

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",
        web3AuthNetwork: .SAPPHIRE_MAINNET,
        redirectUrl: "com.yourapp.bundleid://auth"
    )
)

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"
    )
)

```
