@pradip1995/segment-login-template 0.5.9 → 0.5.10
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.
- package/package.json +6 -6
- package/src/account-profile-logic.ts +6 -2
- package/src/auth-server.ts +32 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pradip1995/segment-login-template",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -22,10 +22,6 @@
|
|
|
22
22
|
"./google-auth-section": "./src/google-auth-section.tsx",
|
|
23
23
|
"./otp-input": "./src/otp-input.tsx"
|
|
24
24
|
},
|
|
25
|
-
"scripts": {
|
|
26
|
-
"typecheck": "tsc --noEmit",
|
|
27
|
-
"lint": "tsc --noEmit"
|
|
28
|
-
},
|
|
29
25
|
"peerDependencies": {
|
|
30
26
|
"@pradip1995/commerce-auth": "^4.0.0",
|
|
31
27
|
"@pradip1995/commerce-core": "^4.0.0",
|
|
@@ -45,5 +41,9 @@
|
|
|
45
41
|
"@types/react": "^19",
|
|
46
42
|
"react": "19.0.3",
|
|
47
43
|
"typescript": "^5.7.2"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"lint": "tsc --noEmit"
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|
|
@@ -130,7 +130,9 @@ export function useAccountProfileLogic(
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
const res = await sendRegistrationOtp(customer.id, type)
|
|
133
|
-
if (!res
|
|
133
|
+
if (!res?.success) {
|
|
134
|
+
throw new Error(res?.error || "Failed to send code")
|
|
135
|
+
}
|
|
134
136
|
setOtpToken(res.token ?? null)
|
|
135
137
|
setOtp("")
|
|
136
138
|
setOtpOpen(true)
|
|
@@ -157,7 +159,9 @@ export function useAccountProfileLogic(
|
|
|
157
159
|
countryCode,
|
|
158
160
|
skipRedirect: true,
|
|
159
161
|
})
|
|
160
|
-
if (!res
|
|
162
|
+
if (!res?.success) {
|
|
163
|
+
throw new Error(res?.error || "Invalid code")
|
|
164
|
+
}
|
|
161
165
|
setOtpOpen(false)
|
|
162
166
|
if (otpType === "phone_verification") {
|
|
163
167
|
setPhoneVerified(true)
|
package/src/auth-server.ts
CHANGED
|
@@ -258,21 +258,42 @@ export async function sendRegistrationOtp(
|
|
|
258
258
|
customerId: string,
|
|
259
259
|
type: "email_verification" | "phone_verification"
|
|
260
260
|
) {
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
261
|
+
const response = await fetch(`${getBaseUrl()}/store/customers/otp/send`, {
|
|
262
|
+
method: "POST",
|
|
263
|
+
headers: getHeaders(),
|
|
264
|
+
body: JSON.stringify({
|
|
265
|
+
customer_id: customerId,
|
|
266
|
+
type,
|
|
267
|
+
}),
|
|
268
|
+
cache: "no-store",
|
|
269
|
+
})
|
|
265
270
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
success: false as const,
|
|
270
|
-
error:
|
|
271
|
-
"Verification email is not configured on the backend. Rebuild and restart the Medusa server with customer-registration OTP settings.",
|
|
271
|
+
if (!response.ok) {
|
|
272
|
+
const err = (await response.json().catch(() => ({}))) as {
|
|
273
|
+
message?: string
|
|
272
274
|
}
|
|
275
|
+
const message = err.message || "Failed to send verification code"
|
|
276
|
+
if (message.includes("Channel configuration not found")) {
|
|
277
|
+
return {
|
|
278
|
+
success: false as const,
|
|
279
|
+
error:
|
|
280
|
+
"Verification is not configured on the backend. Rebuild and restart the Medusa server with customer-registration OTP settings.",
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return { success: false as const, error: message }
|
|
273
284
|
}
|
|
274
285
|
|
|
275
|
-
|
|
286
|
+
const data = (await response.json()) as {
|
|
287
|
+
token?: string
|
|
288
|
+
expires_at?: string
|
|
289
|
+
message?: string
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
success: true as const,
|
|
294
|
+
token: data.token,
|
|
295
|
+
message: data.message || "OTP sent successfully",
|
|
296
|
+
}
|
|
276
297
|
}
|
|
277
298
|
|
|
278
299
|
export async function initiateGoogleAuth(countryCode?: string) {
|