# react-native-otp-code-generator

> react native OTP code generator

Latest version **1.0.2** (published 2025-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-otp-code-generator
pnpm add react-native-otp-code-generator
yarn add react-native-otp-code-generator
bun add react-native-otp-code-generator
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2025-02-19 |
| First published | 2023-07-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 16.0.0 |
| Dependencies | 0 |
| Unpacked size | 41.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | André Kraüss |
| Maintainers | maverick5000 |
| Keywords | react-native, ios, android, otp, totp, 2fa, two-factor-authentication, google-authenticator, authentication, security, one-time-password, time-based-otp, authenticator |

## Links

- npm: https://www.npmjs.com/package/react-native-otp-code-generator
- Repository: https://github.com/Maverick5000/react-native-otp-code-generator
- Homepage: https://github.com/Maverick5000/react-native-otp-code-generator#readme
- Issues: https://github.com/Maverick5000/react-native-otp-code-generator/issues
- npm.io page: https://npm.io/package/react-native-otp-code-generator

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@oxyhq/services](https://npm.io/package/@oxyhq/services.md) — 2.3K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2025-02-19
- 1.0.1 — 2024-03-12
- 0.1.1 — 2023-07-25
- 0.1.0 — 2023-07-25

## README

# React Native OTP Code Generator

A React Native module for generating One-Time Password (OTP) codes using the Time-Based One-Time Password (TOTP) algorithm.

## Installation

### Step 1: Install the module

Install the package from npm:

```bash
npm install react-native-otp-code-generator
```

### Step 2: Link the module (for React Native versions below 0.60)

Link the native module using React Native's CLI:

```bash
react-native link react-native-otp-code-generator
```

## Usage

Import the methods in your JavaScript file:

```javascript
import { generateOtp, generateOtpWithTime, } from 'react-native-otp-code-generator';
```
### Generating an OTP code

To generate a 6-digit OTP code, you can use the `generateOtp` function with callbacks:

```javascript
generateOtp(
  'base32SecretKey',
  (otpcode) => {
    // Use the generated OTP code
    console.log('Generated OTP:', otpcode);
  },
  (errorcode, errorMessage) => {
    console.error(`Error (${errorCode}): ${errorMessage}`);
  }
);
```

### Generating an OTP code with remaining time

To generate a 6-digit OTP code along with the remaining time percentage until the next code is generated, use the `generateOtpWithTime` function with callbacks:

```javascript
generateOtpWithTime(
  'base32SecretKey',
  (otpData) => {
    const { otpcode, timeRemaining } = otpData;
    // Use the generated OTP code and time remaining
    console.log('Generated OTP:', otpcode);
    console.log('Time remaining:', timeRemaining);
  },
  (errorcode, errorMessage) => {
    console.error(`Error (${errorCode}): ${errorMessage}`);
  }
);
```

### Handling Errors

If the provided base32 secret key is invalid or any other error occurs during the OTP code generation process, the error callback will be invoked with an error message. Handle errors using the error callback as shown in the examples above.

---

Please note that this README assumes you have already set up a React Native project and are familiar with the basic concepts of React Native development. If you encounter any issues during installation or usage, refer to the official React Native documentation or open an issue on the library's GitHub repository.

Happy OTP Code Generation! 🚀

---
_Source: https://npm.io/package/react-native-otp-code-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
