hps-plugin-auth-code
By Hyperse
hps-plugin-auth-code is a Auth Code plugin in the Hub Auth group.hps-plugin-auth-code provides Auth Code plugin capabilities for Hub Auth. Authentication, identity, and account access integrations. It is especially useful for auth workflows.
CoreVendure Plugins
Specifications
Technical details and package information for this product.
Package
@hyperse-hub/hps-plugin-auth-code
Support languages
TypeScript, JavaScript, Prolog, Shell, CSS
Last published
July 02, 2026
@hyperse-hub/hps-plugin-auth-code
One-time email verification code authentication for Vendure Shop API.
Features
- Request one-time code: Shop GraphQL
requestOneTimeCode(email) triggers code generation and email delivery
- Sign in / sign up with code: uses Vendure
authenticate + emailCode strategy (creates a Customer/User if not exists)
- Security controls
- TTL (code expiration)
- Max attempts (invalidate after too many failed tries)
- Per-email rate limit (simple window-based limiter)
- Cross-strategy email conflict protection (optional)
Install
Install in your Vendure project:
yarn add @hyperse-hub/hps-plugin-auth-code @hyperse-hub/hps-plugin-email
Note: this plugin relies on @hyperse-hub/hps-plugin-email to render and send the email template.
Vendure configuration
Register the plugin in vendure-config.ts (or your config file):
Options
- attempts: max verification attempts before invalidating the code (default
5)
- ttl: code TTL in milliseconds (default
600000 / 10 minutes)
- length: code length (default
6)
- includeAlphabet: include A–Z letters in the code (default
false, digits only)
- isDev: dev mode. When enabled,
requestOneTimeCode returns the raw code; otherwise it returns a fixed message (default false)
- maxRequestsPerWindow: max requests per email within a window (default
3)
- requestWindowMs: rate limit window in milliseconds (default
60000)
- preventCrossStrategies: enforce unique email across all Shop auth strategies (default
false)
- If enabled and the email is already used by another strategy,
requestOneTimeCode returns CROSS_EMAIL_AUTHENTICATION
Shop API usage
1) Request a one-time code
GraphQL (Shop API):
- Production: returns
value = "A code sent to your email" (fixed message)
- Dev mode (
isDev=true): returns value = "<raw code>" for local testing
The plugin also emits an onetimecode-requested email event. @hyperse-hub/hps-plugin-email renders the template and sends the email.
2) Authenticate with the code (Vendure authenticate)
Once you have the code, call Vendure authenticate using the Shop API field emailCode (strategy name: emailCode):
Note: the input shape above is what this repo uses in e2e tests (authenticate(input: { emailCode: ... })).
Email template
- Event name:
onetimecode-requested
- Template variables:
code
- Template directory: bundled with this plugin (registered automatically on bootstrap)
You can override/customize template loading via @hyperse-hub/hps-plugin-email configuration (see the email plugin docs).
FAQ
I cannot receive emails
- Ensure
@hyperse-hub/hps-plugin-email is installed and enabled
- Verify your SMTP/provider configuration
- For local debugging, enable
isDev=true to get the raw code from the API response
“Too many requests” / rate limited
This is the per-email limiter (maxRequestsPerWindow + requestWindowMs). Tune the values or implement a more advanced limiter at your edge/API layer.
“Invalid verification code”
- The code may be expired (
ttl)
- The code may be invalidated after too many attempts (
attempts)
- Email is normalized to lowercase for caching keys
import { HpsPluginAuthCode } from '@hyperse-hub/hps-plugin-auth-code';
export const config = {
plugins: [
HpsPluginAuthCode.init({
attempts: 5,
ttl: 10 * 60 * 1000,
length: 6,
includeAlphabet: false,
isDev: false,
maxRequestsPerWindow: 3,
requestWindowMs: 60 * 1000,
preventCrossStrategies: false,
}),
],
};
query RequestOneTimeCode($email: String!) {
requestOneTimeCode(email: $email) {
__typename
... on OneTimeCode {
value
}
... on RequestOneTimeCodeError {
errorCode
message
}
}
}
mutation AuthenticateWithEmailCode($email: String!, $code: String!) {
authenticate(input: { emailCode: { email: $email, code: $code } }) {
... on CurrentUser {
identifier
}
... on InvalidCredentialsError {
errorCode
message
authenticationError
}
}
}