Sign in a user
Use the useWeb3AuthConnect hook to sign a user in. Call connectTo with an AUTH_CONNECTION constant and any parameters the connection needs. connectTo resolves with the new connection, or with null if sign-in fails; read error for the reason.
Import
import { useWeb3AuthConnect, AUTH_CONNECTION } from '@web3auth/react-native-sdk'
Usage
- Social login
- Email passwordless
- Custom JWT
import { useWeb3AuthConnect, AUTH_CONNECTION } 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 })}
/>
<Button
title="Sign in with Apple"
disabled={loading}
onPress={() => connectTo({ authConnection: AUTH_CONNECTION.APPLE })}
/>
{error && <Text style={{ color: 'red' }}>{error.message}</Text>}
</View>
)
}
import { useWeb3AuthConnect, AUTH_CONNECTION } from '@web3auth/react-native-sdk'
function EmailLoginView() {
const { connectTo, loading } = useWeb3AuthConnect()
const [email, setEmail] = useState('')
return (
<View>
<TextInput
value={email}
onChangeText={setEmail}
placeholder="Enter your email"
keyboardType="email-address"
autoCapitalize="none"
/>
<Button
title={loading ? 'Sending link…' : 'Continue with email'}
disabled={loading || !email}
onPress={() =>
connectTo({
authConnection: AUTH_CONNECTION.EMAIL_PASSWORDLESS,
extraLoginOptions: { login_hint: email },
})
}
/>
</View>
)
}
import { useWeb3AuthConnect, AUTH_CONNECTION } from '@web3auth/react-native-sdk'
function JwtLoginView() {
const { connectTo, loading } = useWeb3AuthConnect()
const loginWithFirebase = async () => {
// Obtain the idToken from your own authentication flow (Firebase, Auth0, etc.)
const idToken = await getFirebaseIdToken()
await connectTo({
authConnection: AUTH_CONNECTION.CUSTOM,
authConnectionId: 'w3a-firebase-demo', // Dashboard Connection ID
idToken, // no browser opens when you pass an idToken
})
}
return <Button title="Sign in with Firebase" disabled={loading} onPress={loginWithFirebase} />
}
Parameters
- Parameters
- Interface
- AUTH_CONNECTION values
| Parameter | Required | Description |
|---|---|---|
authConnection | Yes | Authentication method. Pass an AUTH_CONNECTION.* constant. |
authConnectionId? | No | Connection ID from the dashboard. Required for AUTH_CONNECTION.CUSTOM and for grouped connections. Also use it to target a specific connection when you have several of the same type. |
groupedAuthConnectionId? | No | Grouped connection ID from the dashboard. Connections in the same group produce the same wallet for the same user. |
idToken? | No | JWT from your own auth provider. When set, the SDK skips the in-app browser and derives the wallet from the token directly. Requires authConnectionId. See Custom authentication. |
extraLoginOptions? | No | Extra OAuth parameters for browser-based sign-in, for example login_hint (email or phone number for passwordless), domain (Auth0 domain), and verifierIdField (JWT claim used as the user ID). |
mfaLevel? | No | When to show the MFA setup screen: 'optional', 'mandatory', or 'none' (MFA_LEVELS.OPTIONAL, MFA_LEVELS.MANDATORY, MFA_LEVELS.NONE). |
curve? | No | Key curve: SUPPORTED_KEY_CURVES.SECP256K1 or SUPPORTED_KEY_CURVES.ED25519. |
dappShare? | No | Dapp share for MFA-enabled custom connections. The SDK stores and reuses the dapp share automatically; see Dapp share. |
appState? | No | Custom state string returned in userInfo.appState after sign-in. |
dappUrl? | No | Custom redirect URL for the manage MFA flow. |
// SdkLoginParams = LoginParams from @web3auth/auth (without getWalletKey) & { idToken?: string }
type SdkLoginParams = {
authConnection: AUTH_CONNECTION_TYPE | CUSTOM_AUTH_CONNECTION_TYPE
authConnectionId?: string
groupedAuthConnectionId?: string
idToken?: string
extraLoginOptions?: ExtraLoginOptions
mfaLevel?: MfaLevelType
curve?: SUPPORTED_KEY_CURVES_TYPE
dappShare?: string
appState?: string
dappUrl?: string
recordId?: string
loginSource?: string
}
Import AUTH_CONNECTION from @web3auth/react-native-sdk.
| Constant | Sign-in method |
|---|---|
AUTH_CONNECTION.GOOGLE | |
AUTH_CONNECTION.FACEBOOK | |
AUTH_CONNECTION.APPLE | Sign in with Apple |
AUTH_CONNECTION.DISCORD | Discord |
AUTH_CONNECTION.TWITTER | X (Twitter) |
AUTH_CONNECTION.GITHUB | GitHub |
AUTH_CONNECTION.REDDIT | |
AUTH_CONNECTION.TWITCH | Twitch |
AUTH_CONNECTION.LINE | LINE |
AUTH_CONNECTION.KAKAO | Kakao |
AUTH_CONNECTION.LINKEDIN | |
AUTH_CONNECTION.WECHAT | |
AUTH_CONNECTION.TELEGRAM | Telegram |
AUTH_CONNECTION.FARCASTER | Farcaster |
AUTH_CONNECTION.EMAIL_PASSWORDLESS | One-time code sent to an email address |
AUTH_CONNECTION.SMS_PASSWORDLESS | One-time code sent to a phone number |
AUTH_CONNECTION.PASSKEYS | Passkey |
AUTH_CONNECTION.AUTHENTICATOR | Authenticator app |
AUTH_CONNECTION.CUSTOM | Custom connection (Auth0, Firebase, any JWT issuer) |