# @semic/plugin-email-code

> A Vendure plugin allow users log in using email and verification code

Latest version **2.2.11** (published 2024-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @semic/plugin-email-code
pnpm add @semic/plugin-email-code
yarn add @semic/plugin-email-code
bun add @semic/plugin-email-code
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.11 |
| Published | 2024-07-19 |
| First published | 2023-07-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=16.0.0 |
| Dependencies | 4 |
| Unpacked size | 136.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Yingchun Tian |
| Maintainers | tianyingchun |

## Links

- npm: https://www.npmjs.com/package/@semic/plugin-email-code
- Repository: https://e.coding.net/kzfoo/kzfoo/kzfoo-srv-2.0
- Homepage: https://e.coding.net/kzfoo/kzfoo/kzfoo-srv-2.0.git
- npm.io page: https://npm.io/package/@semic/plugin-email-code

## Dependencies (4)

- [isemail](https://npm.io/package/isemail.md) 3.2.0
- [@semic/common](https://npm.io/package/@semic/common.md) 2.2.10
- [@semic/plugin-core](https://npm.io/package/@semic/plugin-core.md) 2.2.11
- [@semic/plugin-email](https://npm.io/package/@semic/plugin-email.md) 2.2.11

## Recent versions

- 2.2.11 (latest) — 2024-07-19
- 2.2.10 — 2024-07-11
- 2.2.9 — 2024-06-28
- 2.2.8 — 2024-06-21
- 2.2.7 — 2024-06-06
- 2.2.6 — 2024-06-04
- 2.2.5 — 2024-05-17
- 2.2.4 — 2024-05-11
- 2.2.3 — 2024-05-05
- 2.2.2 — 2024-05-05
- 2.2.1 — 2024-04-26
- 2.2.0 — 2024-04-19
- 2.1.16 — 2024-04-05
- 2.1.15 — 2024-03-22
- 2.1.14 — 2024-03-21
- … 27 more at https://npm.io/package/@semic/plugin-email-code/versions

## README

# @plugin/auth-email-code

A Vendure plugin allow users log in using email and verification code

## Use Case

A lot of times we want visitors (aka customers) to complete their purchase order as quick as possilble. However, they usually hesitate to create a credential to a random online shop at checkout step. So we provide a way to quickly authenticate those visitors by their email and a verification code that is sent to their email.

## What it does

1. Expose a GraphQL Query "`requestOneTimeCode`".
2. Add an authentication strategy to GraphQL mutation "`authenticate`".

---

## How to use

### 1. Install

`yarn add @semic/plugin-auth-email-code`

or

`npm i --save @semic/plugin-auth-email-code`

### 2. Add the plugin to **_vendure-config.ts_** file

```typescript
import { SemicAuthEmailCodePlugin } from "@semic/plugin-auth-email-code";
...
export const config: VendureConfig  = {
 ...
 plugins: [
   ...
   SemicAuthEmailCodePlugin.init(options) //see Options
 ]
}
```

### 3. Options for `SemicAuthEmailCodePlugin.init`

- attempts: `number`
  > Plugin will invalidate the verification code after user's `attempts`.  
  > **default**: 5
- ttl: `number`
  > Time to live  
  > How long the verification code is valid for.  
  > **default**: 600 (seconds)
- length: `number`
  > How many digits/alphabets the verification code should be.  
  > **default**: 6
- includeAlphabet: `boolean`
  > Should allow alphabet characters.  
  > **default**: false (aka `digits only`)
- isDev: `boolean`

  > If true, the verification will return along with the response of query. `requestOneTimeCode`.  
  > It's for debug and testing.  
  > **default**: false

- checkCrossStrategies: `boolean`

  > Strictly enforce unique email among all strategies

  > For example:

  - One day, user "John" sign in using Google authentication with "john@gmail.com".
  - Another day, user "John" sign in using One-time passcode authenication (this plugin) with the same email.
  - This plugin will throw an error if the flag is enabled.

  > **default**: false.  
  > **Note**: This only works if Google authentication plugin using email as an identifier

## Future Updates

- [x] Prevent cross authenticate (Ex: users use same email for GoogleAuth and SimpleAuth)

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