Skip to main content

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.

ParameterDescription
authConnectionIt sets the OAuth login 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 login 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 login. 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 login. It accepts MFALevel as a value.
dappShare?Custom auth connection logins can get a dapp share returned to them post successful login. This is useful if the dapps want to use this share to allow users to login 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 login. 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 login 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 login browser flow. It accepts a string value.

Usage

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

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