customer-registration 0.0.134 → 0.0.135
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -28,7 +28,7 @@ async function lookupCustomerByEmail(scope, email) {
|
|
|
28
28
|
const result = await knex.raw(`SELECT id, email, has_account, first_name, last_name
|
|
29
29
|
FROM customer
|
|
30
30
|
WHERE lower(email) = lower(?)
|
|
31
|
-
ORDER BY created_at DESC
|
|
31
|
+
ORDER BY has_account DESC NULLS LAST, created_at DESC
|
|
32
32
|
LIMIT 1`, [normalized]);
|
|
33
33
|
const row = firstKnexRow(result);
|
|
34
34
|
if (!row?.id) {
|
|
@@ -29,7 +29,7 @@ async function lookupCustomerByPhone(scope, phone) {
|
|
|
29
29
|
const result = await knex.raw(`SELECT id, email, phone, has_account, first_name, last_name
|
|
30
30
|
FROM customer
|
|
31
31
|
WHERE phone = ?
|
|
32
|
-
ORDER BY created_at DESC
|
|
32
|
+
ORDER BY has_account DESC NULLS LAST, created_at DESC
|
|
33
33
|
LIMIT 1`, [normalized]);
|
|
34
34
|
const row = firstKnexRow(result);
|
|
35
35
|
if (!row?.id) {
|
package/README.md
CHANGED
|
@@ -787,6 +787,32 @@ Placeholder module service for registration-related extension points.
|
|
|
787
787
|
5. **Channel-aware password reset**
|
|
788
788
|
Use `/auth/customer/emailpass/reset-password` and `/auth/customer/emailpass/update` with email, phone, or `email_or_phone`.
|
|
789
789
|
|
|
790
|
+
## Known Issues & Fixes
|
|
791
|
+
|
|
792
|
+
### Issue: OTP login treats registered users as new when a guest row also exists
|
|
793
|
+
|
|
794
|
+
**Problem:**
|
|
795
|
+
For some returning users, email/phone OTP verify failed with Medusa's
|
|
796
|
+
`Customer with this email already has an account` (or the phone equivalent).
|
|
797
|
+
Send OTP could also report `is_new_user: true` incorrectly.
|
|
798
|
+
|
|
799
|
+
**Root Cause:**
|
|
800
|
+
Guest checkout and registration can leave two `customer` rows for the same
|
|
801
|
+
email or phone (`has_account = true` and a later `has_account = false` guest).
|
|
802
|
+
OTP lookup used `ORDER BY created_at DESC LIMIT 1`, so it preferred the newer
|
|
803
|
+
guest and the verify flow tried to create another account.
|
|
804
|
+
|
|
805
|
+
**Solution:**
|
|
806
|
+
`lookupCustomerByEmail` / `lookupCustomerByPhone` now order by
|
|
807
|
+
`has_account DESC NULLS LAST, created_at DESC`, so a registered account always
|
|
808
|
+
wins. Guest rows are used only when no registered account exists. No data
|
|
809
|
+
migration is required.
|
|
810
|
+
|
|
811
|
+
**Prevention:**
|
|
812
|
+
- Prefer registered customers (`has_account = true`) in any identifier lookup
|
|
813
|
+
that drives login vs register.
|
|
814
|
+
- Keep regression tests that assert the SQL ordering contract.
|
|
815
|
+
|
|
790
816
|
## Troubleshooting
|
|
791
817
|
|
|
792
818
|
### `storefrontUrl is required when password_reset is configured`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "customer-registration",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.135",
|
|
4
4
|
"description": "Medusa plugin that overrides store customer registration, enforces email/phone verification flags, and provides OTP management module.",
|
|
5
5
|
"author": "Medusa (https://medusajs.com)",
|
|
6
6
|
"license": "MIT",
|