@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pradip1995/segment-login-template",
3
- "version": "0.5.9",
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.success) throw new Error(res.error || "Failed to send code")
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.success) throw new Error(res.error || "Invalid code")
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)
@@ -258,21 +258,42 @@ export async function sendRegistrationOtp(
258
258
  customerId: string,
259
259
  type: "email_verification" | "phone_verification"
260
260
  ) {
261
- const result = await sendCustomerOTP(customerId, type)
262
- if (result.success) {
263
- return result
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
- const message = result.error || "Failed to send verification code"
267
- if (message.includes("Channel configuration not found")) {
268
- return {
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
- return { success: false as const, error: message }
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) {