@tsc_tech/medusa-plugin-auth-passkey
v0.0.10
Published
A starter for Medusa plugins.
Maintainers
Readme
Compatibility
This starter is compatible with versions >= 2.4.0 of @medusajs/medusa.
@tsc_tech/medusa-plugin-auth-passkey
This plugin allows users to register through email and mobile number using OTP. After registration, users are prompted to add a passkey. For already registered users, the generated passkey can be used to log in. If a user does not add a passkey during registration, they can add it later from the account section.
Usage
Registration:
- Users can register using their email or mobile number.
- An OTP will be sent to the provided email or mobile number for verification.
- After successful verification, users will be prompted to add a passkey.
Login:
- Registered users can log in using their email/mobile number and the generated passkey.
- If a user did not add a passkey during registration, they can add it later from their account section.
Adding Passkey:
Users can navigate to the account section to add or update their passkey at any time.
Installation
To install the @tsc_tech/medusa-plugin-auth-passkey, run the following command:
npm install @tsc_tech/medusa-plugin-auth-passkeyor
yarn add @tsc_tech/medusa-plugin-auth-passkeyAdditionally, install the auth-plugin package:
npm install @simplewebauthn/server -D
npm install @simplewebauthn/types -Dor
yarn add @simplewebauthn/server -D
yarn add @simplewebauthn/typesConfiguration
Step 1: Update Medusa Configuration Modify your medusa-config.ts to include the auth provider:
import EmailPassAuthProvider from "@medusajs/medusa/auth-emailpass";
module.exports = defineConfig({
modules: [
...
{
resolve: "@medusajs/medusa/auth",
options: {
providers: [
{
resolve: EmailPassAuthProvider,
id: "emailpass",
},
{
resolve:
"@tsc_tech/medusa-plugin-auth-passkey/providers/auth-passkey",
id: "auth-passkey",
options: {
rpID: process.env.RP_ID,
rpName: process.env.RP_NAME,
enableHTTPS: process.env.ENABLE_HTTPS === "true" ? true : false,
},
},
{
resolve: "@tsc_tech/medusa-plugin-auth-passkey/providers/auth",
id: "otp",
},
],
},
},
...],
plugins: [
{
resolve: "@tsc_tech/medusa-plugin-auth-passkey",
options: {},
},
],
})Run migrations after installation
npx medusa db:migrateStep 2. Set Up Environment Variables In your .env file, define the following variables:
RP_ID=localhost
RP_NAME=your-rp-name
FRONTEND_URL=http://localhost:8000 // your frontend urlStep 3: See the example (auth-passkey-storefront-example) to integrate with frontend (Medusa Starter Template).
Important: You must have a notification provider to send the otp to email or phone.
Features
Secure Authentication: Leverages passkeys for enhanced security.
OTP-based Verification: Ensures user identity with one-time passwords.
Seamless Integration: Easily integrates with Medusa’s authentication system.
Customizable: Environment variables allow configuration for different use cases.
Multi-Platform Support: Works with both email and mobile authentication.
Troubleshooting
If you encounter issues while setting up the plugin, consider the following:
Database Migration Issues: Run npx medusa db:migrate again and ensure your database is correctly set up.
Environment Variables Not Loading: Check if .env is correctly configured and restart your Medusa server.
Passkey Not Prompting: Ensure HTTPS is enabled if running on a production server.
Contribution
We welcome contributions to improve this plugin! If you have suggestions or find issues, feel free to submit a pull request or open an issue in the repository.
