Learn how to customize the @perseidesjs/auth-otp
plugin in your Medusa app
medusa-config.ts
file:
otp
provider, you’re planning to add a new Auth Provider to your Medusa apps, allowing you to create new accounts with OTP-only authentication, if your goal is just to have OTP as a secondary authentication method, do not use this method
and stick to the plugin approach only.digits
: The number of digits in the OTP to generate.ttl
: The time to live for the OTP in seconds before it expires.accessorsPerActor
configuration controls how the plugin identifies and retrieves actors (users, customers or any custom actor) when processing OTP requests. This configuration specifies two critical fields for each actor type:
accessor
: Defines which field is used to initially locate the actor in the database when a request is made. In the example above, customers would be looked up by their email
field.
entityIdAccessor
: Specifies which field from the actor object should be used to find the corresponding auth identity.
accessor
field to find the actor recordentityIdAccessor
field from that actor recordemailpass
provider (which uses email as the entity ID), but want to allow OTP authentication via phone numbers, you would configure:
http
configuration provides options for handling HTTP requests:
alwaysReturnSuccess
: Determines whether the plugin should always return a success response, even if an error occurs. This helps prevent data leakage by ensuring that the response is not affected by errors.
warnOnError
: Logs a warning when an error occurs during OTP generation. This helps you catch and handle errors that might occur during OTP generation.