For AI agents: a documentation index is available at /llms.txt. A markdown version of this page is available at the same URL with .md appended (or via Accept: text/markdown).
Skip to main content

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.

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

Usage​

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.

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

connectTo throws UserCancelledException when the user closes the sign-in flow. On Android, call Web3AuthFlutter.setCustomTabsClosed() when the app resumes so the SDK can detect a closed custom tab. See Handle custom tabs.

try {
final response = await Web3AuthFlutter.connectTo(
LoginParams(authConnection: AuthConnection.google),
);
} on UserCancelledException {
log("User cancelled.");
} on UnKnownException {
log("Unknown exception occurred");
} catch (e) {
log(e.toString());
}

Examples​

Usage
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),
);