Hooks and helpers for user authentication with Clerk Expo SDK.
npm install @ronas-it/clerk-react-native-hooks @clerk/clerk-expo @clerk/types expo-web-browser expo-auth-sessionreact, react-native, and your Clerk/Expo versions should match what @clerk/clerk-expo expects for your Expo SDK.
Hook, that provides access to essential Clerk methods and objects.
Returned object:
signUp— SignUpsignIn— SignInsetActive— sets the active sessionsignOut— signs out the current user
Hook, that provides functionality to handle user sign-up and sign-in processes using an identifier such as an email, phone number, or username. It supports both OTP (One Time Password) and password-based authentication methods.
Parameters:
method: type of identifier ('emailAddress','phoneNumber','username')verifyBy:'otp'or'password'
Returned object:
startSignUp,startSignIn,startAuthorization,isLoading- For email/phone + OTP:
verifyCode,isVerifying(verifyCoderequirescode,isSignUp, optionaltokenTemplate)
Example:
import React, { useState } from 'react';
import { View, TextInput, Button } from 'react-native';
import { useAuthWithIdentifier } from '@ronas-it/clerk-react-native-hooks';
export const AuthWithIdentifierComponent = () => {
const [identifier, setIdentifier] = useState('');
const [verificationCode, setVerificationCode] = useState('');
const { startSignUp, verifyCode, isLoading, isVerifying } = useAuthWithIdentifier('emailAddress', 'otp');
const handleSignUp = async () => {
await startSignUp({ identifier });
};
const handleVerifyCode = async () => {
const result = await verifyCode({ code: verificationCode, isSignUp: true });
console.log(result.sessionToken);
};
return (
<View>
<TextInput
placeholder="Enter your email"
value={identifier}
onChangeText={setIdentifier}
keyboardType="email-address"
/>
<TextInput
placeholder="Enter verification code"
value={verificationCode}
onChangeText={setVerificationCode}
/>
<Button onPress={handleSignUp} title="Sign Up" disabled={isLoading || isVerifying} />
<Button onPress={handleVerifyCode} title="Verify code" disabled={isLoading || isVerifying} />
</View>
);
};Hook for SSO flows.
startSSOFlow—strategy,redirectUrl, optionaltokenTemplateisLoading
Ticket-based auth (token from Backend API).
startAuthorization—ticket, optionaltokenTemplateisLoading
getSessionToken— optional token template
Add email or phone identifiers and verify with codes.
createIdentifier,verifyCode,isCreating,isVerifying
Update primary email or phone: add and verify new identifier, then set primary and remove old.
createIdentifier,verifyCode,isCreating,isVerifying,isUpdating
Lower-level OTP send/verify for sign-in and sign-up.
sendOtpCode,verifyCode,isVerifying
Password reset via email or phone OTP.
startResetPassword,verifyCode,resetPassword,isCodeSending,isResetting,isVerifying
Update the signed-in user's password (currentPassword, newPassword).
updatePassword,isPasswordUpdating
See CONTRIBUTING.md.