Skip to main content

useWeb3AuthConnect

Hook to connect a user to Web3Auth. Call connectTo with an AUTH_CONNECTION constant to open the chosen authentication method in an in-app browser.

Import

import { useWeb3AuthConnect } from '@web3auth/react-native-sdk'

Usage

import { AUTH_CONNECTION, useWeb3AuthConnect } from '@web3auth/react-native-sdk'

function LoginView() {
const { connectTo, loading, error } = useWeb3AuthConnect()

return (
<View>
<Button
title={loading ? 'Signing in…' : 'Sign in with Google'}
disabled={loading}
onPress={() => connectTo({ authConnection: AUTH_CONNECTION.GOOGLE })}
/>
{error && <Text>{error.message}</Text>}
</View>
)
}

Return type

connectTo

(params: SdkLoginParams) => Promise<IProvider | null>

Initiates authentication using the specified method. Opens an in-app browser for the OAuth or magic-link flow and resolves with the EIP-1193 provider on success.

loading

boolean

true while the authentication flow is in progress.

error

Web3AuthError | null

Error from the most recent connectTo call, or null if no error occurred.

isConnected

boolean

true if the user is currently authenticated. Mirrors useWeb3Auth().isConnected.

connectTo parameters

ParameterRequiredDescription
authConnectionYesAuthentication method. Pass an AUTH_CONNECTION.* constant. Replaces the v8 loginProvider field.
authConnectionId?NoDashboard Connection ID for the auth connection. Required when using AUTH_CONNECTION.CUSTOM or when you have multiple connections of the same type and need to target one specifically. Replaces the v8 loginConfig[key].verifier.
groupedAuthConnectionId?NoDashboard Grouped Connection ID when using grouped (aggregate) connections. Connections sharing the same groupedAuthConnectionId produce the same wallet address. Replaces the v8 loginConfig[key].verifierSubIdentifier.
idToken?NoA JWT issued by your authentication provider (Firebase, Auth0, Cognito, and so on). Pass this when using AUTH_CONNECTION.CUSTOM. The token is sent directly to the SDK instead of opening a browser redirect.
extraLoginOptions?NoAdditional OAuth hints passed to the authentication provider. Common fields: login_hint (email), domain (Auth0 domain), verifierIdField (JWT claim to use as the wallet identifier).
redirectUrl?NoOverride the global redirectUrl from web3AuthOptions for this login call only.
mfaLevel?NoOverride the global mfaLevel for this login call only.
curve?NoElliptic curve to use for key generation. Accepts SUPPORTED_KEY_CURVES.SECP256K1 (EVM) or SUPPORTED_KEY_CURVES.ED25519 (Solana). Defaults to the chain namespace.
sessionTime?NoOverride the global session duration (in seconds) for this login session only.
dappShare?NoCustom device share key for MFA-enabled wallets. Required when reconstructing a key with a custom share.
appState?NoArbitrary state string that is returned in the redirect callback. Useful for restoring application state after the OAuth redirect.