SuperTokens authentication provider plugin for Medusa v2. Enables OAuth2/OpenID Connect authentication using SuperTokens as the identity provider.
A Medusa v2 authentication provider plugin that enables session-based authentication using SuperTokens as the identity provider. Compatible with SuperTokens free tier (no OAuth2 license required).
1┌─────────────────┐ ┌─────────────────────┐ ┌─────────────────┐2│ Storefront │ │ hisher-auth │ │ SuperTokens Core│3│ (Next.js) │ │ (Backend API) │ │ (Database) │4│ localhost:3000 │ │ localhost:4002 │ │ localhost:3567 │5└────────┬────────┘ └──────────┬──────────┘ └────────┬────────┘6 │ │ │7 │ 1. Login (OTP/Social) │ │8 │ ───────────────────────>│ │9 │ │ 2. Create session │10 │ │ ────────────────────────>│11 │ 3. Access token │ │12 │ <───────────────────────│ │13 │ │ │14 │ 4. POST /auth/customer/supertokens │15 │ ─────────────────────────────────────┐ │16 │ │ │17 │ ┌─────────────────┴─────────────┴─────┐18 │ │ Medusa Backend │19 │ │ localhost:9000 │20 │ │ │21 │ │ 5. Verify token via /profile/ │22 │ │ verify-token (hisher-auth) │23 │ │ 6. Get user info & metadata │24 │ │ 7. Create/retrieve auth identity │25 │ └─────────────────────────────────────┘26 │ │27 │ 8. Medusa JWT token │28 │ <────────────────────────────────────┘| Service | Port | Description |
|---|---|---|
| Storefront | 3000 | Next.js storefront app |
| SuperTokens Core | 3567 | SuperTokens database/core service |
| hisher-auth Backend | 4002 | SuperTokens backend API with OTP/profile routes |
| hisher-auth Frontend | 4003 | SuperTokens demo UI (optional, for testing) |
| Medusa Backend | 9000 | Medusa e-commerce API |
Note: The hisher-auth frontend (port 4003) is a SuperTokens demo UI showing buttons like "Continue to Store", "Call API", "Logout". It's NOT an admin dashboard - it's designed for authenticated users to test the session. You don't need to run it for production.
1npm install @patiparnne/medusa-supertokens2# or3yarn add @patiparnne/medusa-supertokensAdd the plugin to your :
1import { defineConfig } from '@medusajs/framework/utils';2
3module.exports = defineConfig({4 // ... other config5 modules: [6 {7 resolve: "@medusajs/medusa/auth",8 options: {9 providers: [10 // SuperTokens Authentication Provider11 {12 resolve: "@patiparnne/medusa-supertokens/providers/supertokens-auth",13 id: "supertokens",14 options: {15 // SuperTokens Core URL (for direct session verification)16 coreUrl: process.env.SUPERTOKENS_CORE_URL || "http://localhost:3567",17 18 // hisher-auth Backend API URL (for profile enrichment)19 apiDomain: process.env.SUPERTOKENS_API_DOMAIN || "http://localhost:4002",20 21 // API base path (default: '/auth')22 apiBasePath: process.env.SUPERTOKENS_API_BASE_PATH || "/auth",23 24 // SuperTokens Core API key (if configured)25 apiKey: process.env.SUPERTOKENS_API_KEY,26 27 // Callback URL for redirects (your storefront)28 callbackUrl: process.env.SUPERTOKENS_CALLBACK_URL || "http://localhost:3000/auth/callback",29 30 // Require email verification (default: false)31 verifyEmail: false,32 },33 },34 ],35 },36 },37 ],38 plugins: [39 // SuperTokens plugin - provides /store/auth/supertokens route for customer creation40 {41 resolve: '@patiparnne/medusa-supertokens',42 options: {},43 },44 ],45});Add these to your file:
1# SuperTokens Configuration2SUPERTOKENS_CORE_URL=http://localhost:35673SUPERTOKENS_API_DOMAIN=http://localhost:40024SUPERTOKENS_API_BASE_PATH=/auth5SUPERTOKENS_API_KEY=your-api-key6SUPERTOKENS_CALLBACK_URL=http://localhost:3000/auth/callbackAuthenticate with session token:
1POST /auth/customer/supertokens2Content-Type: application/json3
4{5 "access_token": "<supertokens-session-access-token>"6}Or via Authorization header:
1POST /auth/customer/supertokens2Authorization: Bearer <supertokens-session-access-token>Response (success):
1{2 "token": "<medusa-jwt-token>"3}On every authentication, the plugin calls on hisher-auth to:
This ensures:
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
| string | Yes | - | SuperTokens Core URL (e.g., http://localhost:3567) | |
| string | Yes | - | hisher-auth Backend API URL (e.g., http://localhost:4002) | |
| string | No | API base path for SuperTokens endpoints | ||
| string | No | - | SuperTokens Core API key (for direct Core access) | |
| string | No | - | Redirect URL after login (storefront callback) | |
| boolean | No | Require email verification before allowing auth |
MIT