Allow customers login using email and verification code (One time login)
A Vendure plugin allow users log in using email and verification code
requestOneTimeCode". authenticate".---
yarn add @denz93/vendure-plugin-simple-auth
or
npm i --save @denz93/vendure-plugin-simple-auth
``typescript`
import { SimpleAuthPlugin } from "@denz93/vendure-plugin-simple-auth";
...
export const config: VendureConfig = {
...
plugins: [
...
SimpleAuthPlugin.init(options) //see Options
]
}
* attempts: numberattempts
> Plugin will invalidate the verification code after user's . number
default: 5
* ttl: number
> Time to live
How long the verification code is valid for.
default: 600 (seconds)
* length: boolean
> How many digits/alphabets the verification code should be.
default: 6
* includeAlphabet: digits only
> Should allow alphabet characters.
default: false (aka )boolean
* isDev: requestOneTimeCode
> If true, the verification will return along with the response of query. . CacheModuleOption
It's for debug and testing.
default: false
* cacheModuleOption: "memory"
> By default, the plugin use for caching which is underlying using NestJs CacheModule. Redis
> To change cache store to , MongoDB, etc, please see NestJs CacheModule docs here. cache-manager
> You also want to see here from which is underlying used by NestJs. boolean
> Note: should use cache-manager 4.x if using Vendure under 2.x
> default: {}
* checkCrossStrategies:
> 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
Note**: Since v1.3.0 you don't need to config this step anymore. The plugin will automatically append the handler to Email Plugin
`typescript
// vendure-config.ts
import { oneTimeCodeRequestedEventHandler } from '@denz93/vendure-plugin-simple-auth';
...
export const config: VendureConfig = {
...
plugins: [
...
EmailPlugin.init({
...
handlers: [...defaultEmailHandler, oneTimeCodeRequestedEventHandler]
})
]
}
``
- [x] Prevent cross authenticate (Ex: users use same email for GoogleAuth and SimpleAuth)