Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 0 additions & 153 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,156 +322,3 @@ export default function RootScreen(): ReactElement {
);
}
```

### Features

#### 1. Clerk

> **_NOTE:_** Required dependencies: `@clerk/clerk-expo`, `expo-web-browser`, `expo-auth-session`

Hooks and helpers to create user authentication with [Clerk Expo SDK](https://clerk.com/docs/references/expo/overview).

#### `useClerkResources`

Hook, that provides access to essential Clerk methods and objects.

Returned Object:

- `signUp` - provides access to [SignUp](https://clerk.com/docs/references/javascript/sign-up) object.
- `signIn` - provides access to [SignIn](https://clerk.com/docs/references/javascript/sign-in) object.
- `setActive` - A function that sets the active session.
- `signOut` - A function that signs out the current user.

#### `useAuthWithIdentifier`

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`: Specifies the type of identifier used for authentication (e.g., 'emailAddress', 'phoneNumber', 'username').
- `verifyBy`: Specifies the verification method ('otp' for one-time passwords or 'password').

Returned Object:

- `startSignUp`: Initiates a new user registration using the specified identifier and verification method.
- `startSignIn`: Initiates authentication of an existing user using the specified identifier and verification method.
- `startAuthorization`: Determines whether to initiate a sign-up or sign-in based on whether the user has been registered previously.
- `verifyCode`: Verifies an OTP code if the verification method is 'otp'.
- `isLoading`: Indicates whether an authentication request is in progress.
- `isVerifying`: Indicates whether an OTP verification is in progress.

**Example:**

```ts
import React, { useState } from 'react';
import { View, TextInput, Button } from 'react-native';
import { useAuthWithIdentifier } from '@ronas-it/react-native-common-modules/clerk';

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 });
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>
);
};

```

#### `useAuthWithSSO`

Hook provides functionality to handle [SSO](https://clerk.com/docs/references/expo/use-sso) authentication flows.

Returned Object:

- `startSSOFlow`: A function to initiate an SSO flow. It takes a strategy, redirectUrl, and optional tokenTemplate as parameters, starting the SSO authentication and returning session information or errors upon completion.
- `isLoading`: A boolean indicating whether an SSO process is currently ongoing.

#### `useAuthWithTicket`

This hook is a utility that facilitates user authentication using a ticket-based strategy (ticket is a token generated from the Backend API).

Returned Object:

- `startAuthorization`: A function to initiate authentication with a ticket. It accepts an object with ticket and optional tokenTemplate parameters to kick off the authorization process and returns the session details.
- `isLoading`: A boolean indicating whether the ticket-based authorization process is ongoing.

#### `useGetSessionToken`

This hook is a utility for getting session tokens.

Returned Object:

- `getSessionToken`: A function to retrieve the session token. It takes an optional [tokenTemplate](https://clerk.com/docs/backend-requests/jwt-templates) parameter to specify a template for the token.

#### `useAddIdentifier`

Hook provides functionality to add new email or phone number identifiers to a user's account and verify them using verification codes.

Returned Object:

- `createIdentifier`: A function to add a new email or phone number identifier to the user's account and prepare it for verification.
- `verifyCode`: A function to verify a code sent to the identifier, completing the verification process.
- `isCreating`: A boolean indicating whether an identifier is currently being added.
- `isVerifying`: A boolean indicating whether a verification code is currently being processed.

#### `useUpdateIdentifier`

Hook to update the user's primary identifier (email or phone): add and verify a new one, then set it as primary and remove the old one.

Returned Object:

- `createIdentifier`, `verifyCode`, `isCreating`, `isVerifying`, `isUpdating` — see JSDoc.

#### `useOtpVerification`

Hook provides functionality for managing OTP (One Time Password) verification in user authentication workflows, supporting both sign-up and sign-in processes.

Returned Object:

- `sendOtpCode`: Sends an OTP code to the user's identifier (email or phone number) based on the specified strategy.
- `verifyCode`: Verifies the OTP code provided by the user, completing the authentication process.
- `isVerifying`: A boolean indicating whether a verification attempt is currently in progress.

#### `useResetPassword`

Hook provides methods to handle password reset functionality through email or phone-based OTP.

Returned Object:

- `startResetPassword`: A function to initiate the password reset process by sending a verification code to the user's email or phone number.
- `resetPassword`: A function to reset the user's password by verifying the code and setting a new password.
- `isCodeSending`: A boolean indicating if the verification code is being sent.
- `isResetting`: A boolean indicating if the password is being reset.

#### `useChangePassword`

Hook to update the current user's password (requires current and new password).

Returned Object:

- `updatePassword`, `isPasswordUpdating` — see JSDoc.
Loading
Loading