### Install and Setup ClerkProvider Source: https://context7.com/ronasit/clerk-react-native-hooks/llms.txt Install the package and its peer dependencies. Wrap your root layout with ClerkProvider, providing your publishable key. ```bash npm install @ronas-it/clerk-react-native-hooks @clerk/expo @clerk/types expo-web-browser expo-auth-session expo-secure-store ``` ```tsx import { ClerkProvider } from '@clerk/expo'; import { Slot } from 'expo-router'; export default function RootLayout() { return ( ); } ``` -------------------------------- ### Install Dependencies Source: https://github.com/ronasit/clerk-react-native-hooks/blob/main/CONTRIBUTING.md Run this command to install project dependencies after cloning the repository. ```bash npm install ``` -------------------------------- ### Sign-up with Email/Password Source: https://github.com/ronasit/clerk-react-native-hooks/blob/main/README.md Initiate a sign-up flow using email and password. This example demonstrates capturing user details and handling the sign-up process, potentially leading to an OTP verification step. ```ts const { startSignUp, isLoading } = useAuthWithIdentifier('emailAddress', 'otp'); const onSignUp = async (values: { emailAddress: string; password: string; firstName: string; lastName: string }) => { const { isSuccess, error } = await startSignUp({ identifier: values.emailAddress, password: values.password, firstName: values.firstName, lastName: values.lastName, }); if (isSuccess) { // go to the email OTP step } if (error) { showToast(error?.longMessage); } }; ``` -------------------------------- ### Sign-in with Email and Password Source: https://github.com/ronasit/clerk-react-native-hooks/blob/main/README.md Perform a sign-in operation using email and password. This example shows how to call `startSignIn` and handle potential success or error responses, including the option to use a custom JWT template. ```ts const { startSignIn, isLoading } = useAuthWithIdentifier('emailAddress', 'password'); const onSignIn = async (values: { emailAddress: string; password: string }) => { const { isSuccess, error } = await startSignIn({ identifier: values.emailAddress, password: values.password, tokenTemplate: 'your_jwt_template', }); if (isSuccess) { // handle success } if (error) { showToast(error?.longMessage); } }; ``` -------------------------------- ### Handle Second Factor Authentication with useAuthWithIdentifier and useOtpVerification Source: https://github.com/ronasit/clerk-react-native-hooks/blob/main/README.md This snippet demonstrates how to handle scenarios where a second factor of authentication is required after a successful password sign-in. It uses `useAuthWithIdentifier` to start the sign-in process and `useOtpVerification` to manage the OTP code. ```typescript const { startSignIn } = useAuthWithIdentifier('emailAddress', 'password'); const { sendOtpCode, verifyCode } = useOtpVerification('email_code'); const result = await startSignIn({ identifier, password, tokenTemplate }); if (!result.isSuccess && result.status === 'needs_second_factor') { await sendOtpCode({ isSecondFactor: true }); // await verifyCode({ code, isSecondFactor: true, tokenTemplate }) } ``` -------------------------------- ### Install Clerk React Native Hooks and Dependencies Source: https://github.com/ronasit/clerk-react-native-hooks/blob/main/README.md Install the necessary packages for Clerk authentication in your Expo project. Ensure your React, React Native, and Clerk/Expo versions are compatible. ```sh npm install @ronas-it/clerk-react-native-hooks @clerk/expo @clerk/types expo-web-browser expo-auth-session expo-secure-store ``` -------------------------------- ### useResetPassword Source: https://github.com/ronasit/clerk-react-native-hooks/blob/main/README.md Facilitates the password reset flow using email or phone OTP. It guides through starting the reset, verifying the code, and finally resetting the password. ```APIDOC ## useResetPassword Password reset via email or phone OTP for the forgot-password flow. Use the same `method` (`'emailAddress'` or `'phoneNumber'`) on `useResetPassword` for each step. To **resend** the reset code, call `startResetPassword` again with the **same** `identifier`. 1. `startResetPassword({ identifier })` — sends the reset code (`isCodeSending`); use the same call again to resend. 2. `verifyCode({ code })` — verifies the code (`isVerifying`). 3. `resetPassword({ password, tokenTemplate? })` — applies the new password and finishes sign-in (`isResetting`). #### Example ```ts // 1 — request code const { startResetPassword, isCodeSending } = useResetPassword({ method: 'emailAddress' }); const onRequestCode = async (email: string) => { const { isSuccess, error } = await startResetPassword({ identifier: email }); // if isSuccess → go to code step; keep `email` for resend }; ``` ```ts // 2 — submit code const { verifyCode, isVerifying } = useResetPassword({ method: 'emailAddress' }); const onSubmitCode = async (code: string) => { const { isSuccess, error } = await verifyCode({ code }); // if isSuccess → go to new-password step }; ``` ```ts // Resend — same as step 1: startResetPassword({ identifier }) again const { startResetPassword, isCodeSending } = useResetPassword({ method: 'emailAddress' }); const onResendCode = (email: string) => { startResetPassword({ identifier: email }); }; ``` ```ts // 3 — new password const { resetPassword, isResetting } = useResetPassword({ method: 'emailAddress' }); const onSetNewPassword = async (password: string) => { const { isSuccess, sessionToken, error } = await resetPassword({ password, tokenTemplate: 'your_jwt_template', // optional }); // if isSuccess → handle success }; ``` For SMS, use `{ method: 'phoneNumber' }` and pass the phone number as `identifier`. ``` -------------------------------- ### Sign-up with Email/Password and Separate OTP Verification Source: https://github.com/ronasit/clerk-react-native-hooks/blob/main/README.md This flow uses `useAuthWithIdentifier` for initial sign-up with email and password, then `useOtpVerification` to handle the subsequent OTP verification step. ```ts const { startSignUp, isLoading } = useAuthWithIdentifier('emailAddress', 'password'); const { sendOtpCode } = useOtpVerification('email_code'); await startSignUp({ identifier: values.emailAddress, password: values.password }); await sendOtpCode({ isSignUp: true }); ``` -------------------------------- ### useClerkResources Source: https://github.com/ronasit/clerk-react-native-hooks/blob/main/README.md Returns core Clerk resources such as signUp, signIn, and signOut functionality. ```APIDOC ## useClerkResources ### Description Returns core Clerk resources used by the higher-level hooks. ### Returns - `signUp` — [SignUp](https://clerk.com/docs/expo/reference/objects/sign-in-future) - `signIn` — [SignIn](https://clerk.com/docs/expo/reference/objects/sign-in-future) - `signOut` — signs out the current user ``` -------------------------------- ### SSO Authentication with useAuthWithSSO Source: https://github.com/ronasit/clerk-react-native-hooks/blob/main/README.md Integrates Single Sign-On (SSO) using various strategies like OAuth. Requires `strategy`, `redirectUrl`, and optionally a `tokenTemplate`. The `startSSOFlow` function initiates the SSO process. ```typescript import * as AuthSession from 'expo-auth-session'; const { startSSOFlow, isLoading } = useAuthWithSSO(); const onGooglePress = async () => { const { isSuccess, error } = await startSSOFlow({ strategy: 'oauth_google', redirectUrl: AuthSession.makeRedirectUri({ path: navigationConfig.auth.signUp }), tokenTemplate: 'your_jwt_template', // optional }); if (isSuccess) { // handle success } if (error) { showToast(error?.longMessage); } }; ``` -------------------------------- ### Sign-in or Sign-up with Email/Phone OTP Source: https://github.com/ronasit/clerk-react-native-hooks/blob/main/README.md Use this hook for flows where sign-in and sign-up share a single identifier (email or phone). It supports the `signUpIfMissing` option to send OTP even if the account doesn't exist. The first screen initiates the sign-in/sign-up process, and the second screen handles OTP verification. ```typescript const { startSignIn, isLoading } = useAuthWithIdentifier('emailAddress', 'otp'); const onContinue = async (email: string) => { const { error, isSuccess } = await startSignIn({ identifier: email, signUpIfMissing: true }); if (isSuccess) { // go to OTP step (same hook instance keeps signIn / signUp resources) } if (error) { showToast(error?.longMessage); } }; ``` ```typescript const { verifyCode, isVerifying } = useAuthWithIdentifier('emailAddress', 'otp'); const onVerify = async (code: string) => { const { sessionToken, error, isSuccess, signUp } = await verifyCode({ code, tokenTemplate: 'your_jwt_template', }); if (isSuccess) { // handle success } if (error) { showToast(error?.longMessage); } }; ``` -------------------------------- ### useAuthWithIdentifier (Sign-in/Sign-up with OTP) Source: https://github.com/ronasit/clerk-react-native-hooks/blob/main/README.md Handles sign-in and sign-up flows using an email or phone number and an OTP. It supports the `signUpIfMissing` option to allow verification even if the user account doesn't exist yet. ```APIDOC ## useAuthWithIdentifier (Sign-in/Sign-up with OTP) ### Description Use this hook when sign-in and sign-up share one identifier (email or phone). It facilitates Clerk’s `signUpIfMissing` flow so verification runs even if the account does not exist yet. ### First Screen - Start Sign In ```ts const { startSignIn, isLoading } = useAuthWithIdentifier('emailAddress', 'otp'); const onContinue = async (email: string) => { const { error, isSuccess } = await startSignIn({ identifier: email, signUpIfMissing: true }); if (isSuccess) { // go to OTP step (same hook instance keeps signIn / signUp resources) } if (error) { showToast(error?.longMessage); } }; ``` ### OTP Screen - Verify Code ```ts const { verifyCode, isVerifying } = useAuthWithIdentifier('emailAddress', 'otp'); const onVerify = async (code: string) => { const { sessionToken, error, isSuccess, signUp } = await verifyCode({ code, tokenTemplate: 'your_jwt_template' }); if (isSuccess) { // handle success } if (error) { showToast(error?.longMessage); } }; ``` ### Notes On the code screen, `useOtpVerification` can be used for resend/verify. Use `isSignUp: false` for `sendOtpCode` and `verifyCode` on this path to maintain correct transfer behavior. ``` -------------------------------- ### Unified Sign-in/Sign-up with OTP using useAuthWithIdentifier Source: https://context7.com/ronasit/clerk-react-native-hooks/llms.txt Provides a single identifier field for both sign-in and sign-up with OTP. The startSignIn function can be used with `signUpIfMissing: true` to send OTP even if no account exists. ```tsx import { useAuthWithIdentifier } from '@ronas-it/clerk-react-native-hooks'; // --- Sign-in-or-up (single identifier field) --- function UnifiedAuthScreen() { const { startSignIn, verifyCode, isLoading, isVerifying } = useAuthWithIdentifier('emailAddress', 'otp'); const onContinue = async (email: string) => { // signUpIfMissing: Clerk sends OTP even if no account exists yet const { isSuccess, error } = await startSignIn({ identifier: email, signUpIfMissing: true }); if (!isSuccess) Alert.alert('Error', String(error)); }; const onVerify = async (code: string) => { const { isSuccess, sessionToken, signUp, error } = await verifyCode({ code }); if (isSuccess) { const isNewUser = !!signUp?.createdUserId; console.log(isNewUser ? 'New user registered' : 'Existing user signed in', sessionToken); } if (error) Alert.alert('Error', String(error)); }; } ``` -------------------------------- ### Passwordless Sign-up and Sign-in with OTP Source: https://github.com/ronasit/clerk-react-native-hooks/blob/main/README.md Use `useAuthWithIdentifier` for passwordless authentication via email or phone OTP. Handles both new user sign-up and existing user sign-in flows. ```ts const { startSignUp, startSignIn, verifyCode } = useAuthWithIdentifier('emailAddress', 'otp'); // useAuthWithIdentifier('phoneNumber', 'otp') for SMS await startSignUp({ identifier }); // new user await verifyCode({ code, isSignUp: true, tokenTemplate }); await startSignIn({ identifier }); // existing user await verifyCode({ code, tokenTemplate }); ``` ```ts const { verifyCode, sendOtpCode } = useOtpVerification('email_code'); // SMS: useOtpVerification('phone_code') await sendOtpCode({ isSignUp: true }); await verifyCode({ code, isSignUp: true, tokenTemplate }); ``` -------------------------------- ### Configure ClerkProvider in RootLayout Source: https://github.com/ronasit/clerk-react-native-hooks/blob/main/README.md Wrap your root layout with ClerkProvider from @clerk/expo and provide your Clerk publishable key. This sets up the Clerk context for your application. ```tsx import { ClerkProvider } from '@clerk/expo'; import { Slot } from 'expo-router'; export default function RootLayout() { return ( ); } ``` -------------------------------- ### Push Changes and Tags Source: https://github.com/ronasit/clerk-react-native-hooks/blob/main/CONTRIBUTING.md After bumping the version, push the commit and the newly created tag to the remote repository. ```bash git push && git push --tags ``` -------------------------------- ### useAuthWithSSO Source: https://context7.com/ronasit/clerk-react-native-hooks/llms.txt Initiates an OAuth SSO flow (Google, GitHub, Apple, etc.) using expo-auth-session and expo-web-browser. Returns a sessionToken on success. ```APIDOC ## `useAuthWithSSO` — Social / OAuth Sign-In Initiates an OAuth SSO flow (Google, GitHub, Apple, etc.) using `expo-auth-session` and `expo-web-browser`. Returns a `sessionToken` on success. ### Usage ```tsx import * as AuthSession from 'expo-auth-session'; import { useAuthWithSSO } from '@ronas-it/clerk-react-native-hooks'; function SocialAuthButtons() { const { startSSOFlow, isLoading } = useAuthWithSSO(); const signInWith = async (provider: 'oauth_google' | 'oauth_github' | 'oauth_apple') => { const { isSuccess, sessionToken, error } = await startSSOFlow({ strategy: provider, redirectUrl: AuthSession.makeRedirectUri({ path: '/auth/callback' }), tokenTemplate: 'my_jwt_template', // optional }); if (isSuccess) console.log('SSO token:', sessionToken); if (error) Alert.alert('SSO Error', String(error)); }; return (