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
- Email passwordless
- Custom JWT
- Grouped connection
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>
)
}
import { AUTH_CONNECTION, useWeb3AuthConnect } from '@web3auth/react-native-sdk'
function EmailLogin() {
const { connectTo, loading } = useWeb3AuthConnect()
const [email, setEmail] = useState('')
return (
<View>
<TextInput value={email} onChangeText={setEmail} placeholder="your@email.com" />
<Button
title="Continue with email"
disabled={loading}
onPress={() =>
connectTo({
authConnection: AUTH_CONNECTION.EMAIL_PASSWORDLESS,
extraLoginOptions: { login_hint: email },
})
}
/>
</View>
)
}
import { AUTH_CONNECTION, useWeb3AuthConnect } from '@web3auth/react-native-sdk'
async function loginWithFirebase(idToken: string) {
const { connectTo } = useWeb3AuthConnect()
await connectTo({
authConnection: AUTH_CONNECTION.CUSTOM,
authConnectionId: 'w3a-firebase-demo', // Dashboard Connection ID
idToken, // JWT from your provider
extraLoginOptions: { verifierIdField: 'sub' },
})
}
import { AUTH_CONNECTION, useWeb3AuthConnect } from '@web3auth/react-native-sdk'
function GroupedLoginView() {
const { connectTo, loading } = useWeb3AuthConnect()
const loginWithGoogle = () =>
connectTo({
authConnection: AUTH_CONNECTION.GOOGLE,
authConnectionId: 'w3a-google',
groupedAuthConnectionId: 'aggregate-sapphire',
})
const loginWithEmail = () =>
connectTo({
authConnection: AUTH_CONNECTION.EMAIL_PASSWORDLESS,
authConnectionId: 'w3a-a0-email-passwordless',
groupedAuthConnectionId: 'aggregate-sapphire', // same group → same wallet
})
return (
<View>
<Button title="Google" disabled={loading} onPress={loginWithGoogle} />
<Button title="Email" disabled={loading} onPress={loginWithEmail} />
</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
- Parameters
- Interface
- AUTH_CONNECTION enum
| Parameter | Required | Description |
|---|---|---|
authConnection | Yes | Authentication method. Pass an AUTH_CONNECTION.* constant. Replaces the v8 loginProvider field. |
authConnectionId? | No | Dashboard 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? | No | Dashboard 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? | No | A 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? | No | Additional 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? | No | Override the global redirectUrl from web3AuthOptions for this login call only. |
mfaLevel? | No | Override the global mfaLevel for this login call only. |
curve? | No | Elliptic curve to use for key generation. Accepts SUPPORTED_KEY_CURVES.SECP256K1 (EVM) or SUPPORTED_KEY_CURVES.ED25519 (Solana). Defaults to the chain namespace. |
sessionTime? | No | Override the global session duration (in seconds) for this login session only. |
dappShare? | No | Custom device share key for MFA-enabled wallets. Required when reconstructing a key with a custom share. |
appState? | No | Arbitrary state string that is returned in the redirect callback. Useful for restoring application state after the OAuth redirect. |
export interface SdkLoginParams {
/** Authentication method — use AUTH_CONNECTION.* constants */
authConnection: AUTH_CONNECTION_TYPE
/** Dashboard Connection ID; required for AUTH_CONNECTION.CUSTOM */
authConnectionId?: string
/** Grouped Connection ID for aggregate verifier flows */
groupedAuthConnectionId?: string
/** JWT from your auth provider for custom authentication */
idToken?: string
/** Additional OAuth parameters (login_hint, domain, verifierIdField, etc.) */
extraLoginOptions?: ExtraLoginOptions
/** Override redirectUrl for this login call */
redirectUrl?: string
/** Override MFA level for this login call */
mfaLevel?: MfaLevelType
/** Elliptic curve for key generation */
curve?: SUPPORTED_KEY_CURVES_TYPE
/** Override session duration for this session */
sessionTime?: number
/** Custom device share for MFA-enabled wallets */
dappShare?: string
/** Arbitrary app state to restore after redirect */
appState?: string
}
AUTH_CONNECTION replaces the v8 LOGIN_PROVIDER enum. Import it from @web3auth/react-native-sdk.
AUTH_CONNECTION constant | Description | v8 LOGIN_PROVIDER equivalent |
|---|---|---|
AUTH_CONNECTION.GOOGLE | Google OAuth 2.0 | LOGIN_PROVIDER.GOOGLE |
AUTH_CONNECTION.FACEBOOK | Facebook OAuth | LOGIN_PROVIDER.FACEBOOK |
AUTH_CONNECTION.APPLE | Sign in with Apple | LOGIN_PROVIDER.APPLE |
AUTH_CONNECTION.DISCORD | Discord OAuth | LOGIN_PROVIDER.DISCORD |
AUTH_CONNECTION.TWITTER | Twitter / X OAuth | LOGIN_PROVIDER.TWITTER |
AUTH_CONNECTION.GITHUB | GitHub OAuth | LOGIN_PROVIDER.GITHUB |
AUTH_CONNECTION.TWITCH | Twitch OAuth | LOGIN_PROVIDER.TWITCH |
AUTH_CONNECTION.LINE | LINE OAuth | LOGIN_PROVIDER.LINE |
AUTH_CONNECTION.KAKAO | Kakao OAuth | LOGIN_PROVIDER.KAKAO |
AUTH_CONNECTION.LINKEDIN | LinkedIn OAuth | LOGIN_PROVIDER.LINKEDIN |
AUTH_CONNECTION.WEIBO | Weibo OAuth | LOGIN_PROVIDER.WEIBO |
AUTH_CONNECTION.WECHAT | WeChat OAuth | LOGIN_PROVIDER.WECHAT |
AUTH_CONNECTION.EMAIL_PASSWORDLESS | Magic link / OTP sent to an email address | LOGIN_PROVIDER.EMAIL_PASSWORDLESS |
AUTH_CONNECTION.SMS_PASSWORDLESS | OTP sent to a phone number | LOGIN_PROVIDER.SMS_PASSWORDLESS |
AUTH_CONNECTION.FARCASTER | Farcaster protocol sign-in | — |
AUTH_CONNECTION.CUSTOM | Any custom JWT flow (Firebase, Auth0, Cognito, and so on) | LOGIN_PROVIDER.JWT |