# @email-otp-auth/redis

> Otp based Authentication package made to streamline the process of otp based Authentication

Latest version **1.0.0** (published 2024-01-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @email-otp-auth/redis
pnpm add @email-otp-auth/redis
yarn add @email-otp-auth/redis
bun add @email-otp-auth/redis
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-01-15 |
| First published | 2023-12-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 21.5 KB |
| Known vulnerabilities | 0 (+15 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Aditya Gupta |
| Maintainers | dev-adi |
| Keywords | Authentication, otp, Redis, Mailer |

## Links

- npm: https://www.npmjs.com/package/@email-otp-auth/redis
- Repository: https://github.com/Adityagupta1625/otp-auth
- Homepage: https://github.com/Adityagupta1625/otp-auth#readme
- Issues: https://github.com/Adityagupta1625/otp-auth/issues
- npm.io page: https://npm.io/package/@email-otp-auth/redis

## Dependencies (5)

- [redis](https://npm.io/package/redis.md) ^4.6.11
- [nodemailer](https://npm.io/package/nodemailer.md) ^6.9.7
- [otp-generator](https://npm.io/package/otp-generator.md) ^4.0.1
- [@types/nodemailer](https://npm.io/package/@types/nodemailer.md) ^6.4.14
- [@types/otp-generator](https://npm.io/package/@types/otp-generator.md) ^4.0.2

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2024-01-15
- 0.0.2 — 2023-12-04
- 0.0.1 — 2023-12-04

## README

# Email OTP Auth/Redis

This package provies a stremaline way for authentication service using email OTP.This service utilizes Redis for storing and verifying OTPs and a mail server for sending OTPs via email.

## Configuration

### Mail Server Configuration

Make sure to configure the mail server settings by providing the necessary information in the `MailServerConfiguration` interface. The interface is defined as follows:

```typescript
interface MailServerConfiguration {
  host: string; // The host name of the mail server.
  port: number; // The port number for connecting to the mail server.
  email: string; // The email address used for authentication.
  pass: string; // The app password associated with the email address for authentication. You can refer google for app password.
  name: string; // The name associated with the sender of the email.
  subject: string; // The subject of the email.
  body: string; // The body or content of the email with template {{otp}} for otp replacement.
}
```

### Redis Configuration

Set up a Redis DB URL.

### Auth Class Configruation

```typescript
const auth = new Auth('YOUR_REDIS_URL', mailServerConfig);
```

## Usage

### Generate OTP

To generate and send an OTP to a specified email address, use the following code snippet:

```typescript
const email = 'user@example.com';

try {
  await auth.generateOTP(email);
  console.log(`OTP sent successfully to ${email}`);
} catch (error) {
  console.error(`Error sending OTP: ${error.message}`);
}
```

### Verify OTP

To verify an OTP for a specified email address, use the following code snippet:

```typescript
const email = 'user@example.com';
const userEnteredOTP = '123456'; // Replace with the actual OTP entered by the user

try {
  const isOTPValid = await auth.verifyOTP(email, userEnteredOTP);
  if (isOTPValid) {
    console.log('OTP is valid');
  } else {
    console.log('Invalid OTP');
  }
} catch (error) {
  console.error(`Error verifying OTP: ${error.message}`);
}
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---
_Source: https://npm.io/package/@email-otp-auth/redis · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
