@pradip1995/segment-login-template 0.5.24 → 0.5.26

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.
Files changed (38) hide show
  1. package/package.json +54 -54
  2. package/src/account-addresses.tsx +287 -287
  3. package/src/account-guest-orders.tsx +98 -98
  4. package/src/account-orders.tsx +260 -260
  5. package/src/account-overview.tsx +133 -133
  6. package/src/account-payment-methods.tsx +328 -328
  7. package/src/account-profile-logic.ts +282 -282
  8. package/src/account-profile.tsx +111 -111
  9. package/src/account-theme.ts +91 -91
  10. package/src/account-utils.ts +20 -20
  11. package/src/auth-server.ts +442 -442
  12. package/src/commerce-auth-otp-modal.css +125 -125
  13. package/src/commerce-auth-otp-modal.tsx +121 -121
  14. package/src/forgot-password-form.tsx +109 -109
  15. package/src/google-auth-section.tsx +22 -22
  16. package/src/google-sign-in-section.tsx +67 -142
  17. package/src/guest-order-modal.tsx +215 -215
  18. package/src/index.ts +7 -7
  19. package/src/is-next-redirect.ts +60 -60
  20. package/src/login-brand-panel.tsx +158 -158
  21. package/src/login-form.tsx +469 -469
  22. package/src/manifest.ts +11 -11
  23. package/src/order-history-status.test.ts +224 -224
  24. package/src/order-history-status.ts +244 -244
  25. package/src/otp-component.ts +14 -14
  26. package/src/otp-input.tsx +46 -46
  27. package/src/otp-unified-form.tsx +333 -333
  28. package/src/otp-verification-modal.tsx +112 -112
  29. package/src/payment-methods-actions.ts +243 -243
  30. package/src/profile-email-field.tsx +116 -116
  31. package/src/profile-email.test.ts +182 -182
  32. package/src/profile-email.ts +54 -54
  33. package/src/profile-phone-field.tsx +119 -119
  34. package/src/register-form.tsx +339 -339
  35. package/src/reorder-checkout-address.ts +101 -101
  36. package/src/reset-password-form.tsx +103 -103
  37. package/src/reset-password-page.tsx +12 -12
  38. package/src/segment.tsx +272 -272
@@ -1,109 +1,109 @@
1
- "use client"
2
-
3
- import { isNextRedirect, safeErrorMessage } from "./is-next-redirect"
4
- import { useState } from "react"
5
- import { checkEmailRegistered, requestPasswordReset } from "./auth-server"
6
- import { auth } from "./account-theme"
7
- import { AuthField, Ornament } from "./login-form"
8
-
9
- export default function ForgotPasswordForm({ onBack }: { onBack: () => void }) {
10
- const [email, setEmail] = useState("")
11
- const [message, setMessage] = useState<string | null>(null)
12
- const [error, setError] = useState<string | null>(null)
13
- const [pending, setPending] = useState(false)
14
- const [success, setSuccess] = useState(false)
15
-
16
- async function handleSubmit(e: React.FormEvent) {
17
- e.preventDefault()
18
- if (!email.trim()) return
19
-
20
- setPending(true)
21
- setMessage(null)
22
- setError(null)
23
-
24
- try {
25
- const check = await checkEmailRegistered(email.trim())
26
- if (!check.exists) {
27
- setError("This email is not registered. Please create a new account instead.")
28
- return
29
- }
30
-
31
- const result = await requestPasswordReset(email.trim())
32
- if (!result.success) {
33
- setError(result.error || "Failed to send reset link")
34
- return
35
- }
36
-
37
- setSuccess(true)
38
- setMessage(result.message || "If an account exists, you will receive a reset link shortly.")
39
- } catch (err) {
40
- if (isNextRedirect(err)) throw err
41
- setError(safeErrorMessage(err, "Something went wrong"))
42
- } finally {
43
- setPending(false)
44
- }
45
- }
46
-
47
- if (success) {
48
- return (
49
- <div className="space-y-5 text-center py-4">
50
- <Ornament />
51
- <div className="w-14 h-14 mx-auto rounded-full bg-brand-accent/10 flex items-center justify-center text-brand-accent">
52
- <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" aria-hidden>
53
- <path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z" />
54
- <polyline points="22,6 12,13 2,6" />
55
- </svg>
56
- </div>
57
- <h2 className={`${auth.title} text-xl`}>Check your email</h2>
58
- <p className="text-sm text-muted">{message}</p>
59
- <button type="button" onClick={onBack} className={auth.btnOutline}>
60
- Back to sign in
61
- </button>
62
- </div>
63
- )
64
- }
65
-
66
- return (
67
- <form onSubmit={handleSubmit} className="space-y-5">
68
- <div className="text-center lg:text-left">
69
- <Ornament />
70
- <h2 className={`${auth.title} text-xl lg:text-2xl`}>Reset password</h2>
71
- <p className="mt-2 text-sm text-muted">
72
- Enter your email and we&apos;ll send a link to reset your password.
73
- </p>
74
- </div>
75
-
76
- <AuthField
77
- label="Email"
78
- name="email"
79
- type="email"
80
- value={email}
81
- onChange={(e) => setEmail(e.target.value)}
82
- autoComplete="email"
83
- placeholder="you@example.com"
84
- />
85
-
86
- {error && (
87
- <p className="text-sm text-brand-sale" role="alert">
88
- {error}
89
- </p>
90
- )}
91
-
92
- <button
93
- type="submit"
94
- disabled={pending}
95
- className={`${auth.btnPrimary} ${auth.btnShine}`}
96
- >
97
- <span className="relative z-[1]">{pending ? "Sending…" : "Send reset link"}</span>
98
- </button>
99
-
100
- <button
101
- type="button"
102
- onClick={onBack}
103
- className="text-sm text-muted hover:text-brand-accent w-full text-center transition-colors"
104
- >
105
- Back to sign in
106
- </button>
107
- </form>
108
- )
109
- }
1
+ "use client"
2
+
3
+ import { isNextRedirect, safeErrorMessage } from "./is-next-redirect"
4
+ import { useState } from "react"
5
+ import { checkEmailRegistered, requestPasswordReset } from "./auth-server"
6
+ import { auth } from "./account-theme"
7
+ import { AuthField, Ornament } from "./login-form"
8
+
9
+ export default function ForgotPasswordForm({ onBack }: { onBack: () => void }) {
10
+ const [email, setEmail] = useState("")
11
+ const [message, setMessage] = useState<string | null>(null)
12
+ const [error, setError] = useState<string | null>(null)
13
+ const [pending, setPending] = useState(false)
14
+ const [success, setSuccess] = useState(false)
15
+
16
+ async function handleSubmit(e: React.FormEvent) {
17
+ e.preventDefault()
18
+ if (!email.trim()) return
19
+
20
+ setPending(true)
21
+ setMessage(null)
22
+ setError(null)
23
+
24
+ try {
25
+ const check = await checkEmailRegistered(email.trim())
26
+ if (!check.exists) {
27
+ setError("This email is not registered. Please create a new account instead.")
28
+ return
29
+ }
30
+
31
+ const result = await requestPasswordReset(email.trim())
32
+ if (!result.success) {
33
+ setError(result.error || "Failed to send reset link")
34
+ return
35
+ }
36
+
37
+ setSuccess(true)
38
+ setMessage(result.message || "If an account exists, you will receive a reset link shortly.")
39
+ } catch (err) {
40
+ if (isNextRedirect(err)) throw err
41
+ setError(safeErrorMessage(err, "Something went wrong"))
42
+ } finally {
43
+ setPending(false)
44
+ }
45
+ }
46
+
47
+ if (success) {
48
+ return (
49
+ <div className="space-y-5 text-center py-4">
50
+ <Ornament />
51
+ <div className="w-14 h-14 mx-auto rounded-full bg-brand-accent/10 flex items-center justify-center text-brand-accent">
52
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" aria-hidden>
53
+ <path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z" />
54
+ <polyline points="22,6 12,13 2,6" />
55
+ </svg>
56
+ </div>
57
+ <h2 className={`${auth.title} text-xl`}>Check your email</h2>
58
+ <p className="text-sm text-muted">{message}</p>
59
+ <button type="button" onClick={onBack} className={auth.btnOutline}>
60
+ Back to sign in
61
+ </button>
62
+ </div>
63
+ )
64
+ }
65
+
66
+ return (
67
+ <form onSubmit={handleSubmit} className="space-y-5">
68
+ <div className="text-center lg:text-left">
69
+ <Ornament />
70
+ <h2 className={`${auth.title} text-xl lg:text-2xl`}>Reset password</h2>
71
+ <p className="mt-2 text-sm text-muted">
72
+ Enter your email and we&apos;ll send a link to reset your password.
73
+ </p>
74
+ </div>
75
+
76
+ <AuthField
77
+ label="Email"
78
+ name="email"
79
+ type="email"
80
+ value={email}
81
+ onChange={(e) => setEmail(e.target.value)}
82
+ autoComplete="email"
83
+ placeholder="you@example.com"
84
+ />
85
+
86
+ {error && (
87
+ <p className="text-sm text-brand-sale" role="alert">
88
+ {error}
89
+ </p>
90
+ )}
91
+
92
+ <button
93
+ type="submit"
94
+ disabled={pending}
95
+ className={`${auth.btnPrimary} ${auth.btnShine}`}
96
+ >
97
+ <span className="relative z-[1]">{pending ? "Sending…" : "Send reset link"}</span>
98
+ </button>
99
+
100
+ <button
101
+ type="button"
102
+ onClick={onBack}
103
+ className="text-sm text-muted hover:text-brand-accent w-full text-center transition-colors"
104
+ >
105
+ Back to sign in
106
+ </button>
107
+ </form>
108
+ )
109
+ }
@@ -1,22 +1,22 @@
1
- "use client"
2
-
3
- import { GoogleSignInSection } from "./google-sign-in-section"
4
- import { auth } from "./account-theme"
5
-
6
- export default function GoogleAuthSection({
7
- countryCode,
8
- enableOneTap = true,
9
- }: {
10
- countryCode: string
11
- enableOneTap?: boolean
12
- }) {
13
- return (
14
- <GoogleSignInSection
15
- countryCode={countryCode}
16
- defaultCountryCode="in"
17
- enableOneTap={enableOneTap}
18
- credentialButtonClassName={`${auth.btnOutline} sr-google-btn`}
19
- oauthButtonClassName={`${auth.btnOutline} sr-google-btn`}
20
- />
21
- )
22
- }
1
+ "use client"
2
+
3
+ import { GoogleSignInSection } from "./google-sign-in-section"
4
+ import { auth } from "./account-theme"
5
+
6
+ export default function GoogleAuthSection({
7
+ countryCode,
8
+ enableOneTap = true,
9
+ }: {
10
+ countryCode: string
11
+ enableOneTap?: boolean
12
+ }) {
13
+ return (
14
+ <GoogleSignInSection
15
+ countryCode={countryCode}
16
+ defaultCountryCode="in"
17
+ enableOneTap={enableOneTap}
18
+ credentialButtonClassName={`${auth.btnOutline} sr-google-btn`}
19
+ oauthButtonClassName={`${auth.btnOutline} sr-google-btn`}
20
+ />
21
+ )
22
+ }
@@ -1,142 +1,67 @@
1
- "use client"
2
-
3
- import { useEffect, useMemo, useState } from "react"
4
- import { GoogleAuthProvider } from "@pradip1995/commerce-auth/components/google-oauth-provider"
5
- import { GoogleCredentialButton } from "@pradip1995/commerce-auth/components/google-credential-button"
6
- import { GoogleIdentityServicesScript } from "@pradip1995/commerce-auth/components/google-identity-script"
7
- import { GoogleLoginButton } from "@pradip1995/commerce-auth/components/google-login"
8
- import { GoogleOneTapLogin } from "@pradip1995/commerce-auth/components/google-one-tap"
9
- import {
10
- authenticateGoogleCredential,
11
- handleGoogleCallback,
12
- initiateGoogleAuth,
13
- } from "./auth-server"
14
-
15
- type GisUiState = "loading" | "ready" | "fallback"
16
-
17
- const ORIGIN_REJECTED = /origin is not allowed|origin_mismatch|unregistered_origin/i
18
-
19
- function useGsiOriginWatch(onRejected: () => void) {
20
- useEffect(() => {
21
- if (typeof window === "undefined" || window.__vnGsiConsolePatched) return
22
- window.__vnGsiConsolePatched = true
23
- const original = console.error
24
- console.error = (...args: unknown[]) => {
25
- const text = args.map((a) => (typeof a === "string" ? a : String(a))).join(" ")
26
- if (text.includes("[GSI_LOGGER]") && ORIGIN_REJECTED.test(text)) {
27
- onRejected()
28
- console.warn(...args)
29
- return
30
- }
31
- original(...args)
32
- }
33
- return () => {
34
- console.error = original
35
- window.__vnGsiConsolePatched = false
36
- }
37
- }, [onRejected])
38
- }
39
-
40
- declare global {
41
- interface Window {
42
- __vnGsiConsolePatched?: boolean
43
- }
44
- }
45
-
46
- /**
47
- * Google Sign-In for Medusa storefronts: GIS "Continue as {email}" button,
48
- * One Tap prompt, and OAuth redirect fallback (same pattern as VyaparNext deployer).
49
- */
50
- export function GoogleSignInSection({
51
- countryCode,
52
- defaultCountryCode = "in",
53
- enableOneTap = true,
54
- credentialButtonClassName,
55
- oauthButtonClassName,
56
- onError,
57
- }: {
58
- countryCode: string
59
- defaultCountryCode?: string
60
- enableOneTap?: boolean
61
- credentialButtonClassName?: string
62
- oauthButtonClassName?: string
63
- onError?: (message: string) => void
64
- }) {
65
- const clientId = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID?.trim()
66
- const [gis, setGis] = useState<GisUiState>("loading")
67
- const [error, setError] = useState<string | null>(null)
68
-
69
- const handlers = useMemo(
70
- () => ({
71
- authenticateCredential: authenticateGoogleCredential,
72
- handleCustomerCallback: handleGoogleCallback,
73
- }),
74
- []
75
- )
76
-
77
- useGsiOriginWatch(() => setGis("fallback"))
78
-
79
- useEffect(() => {
80
- if (!clientId || gis === "fallback") return
81
- const timer = window.setTimeout(() => {
82
- setGis((s) => (s === "fallback" ? s : "ready"))
83
- }, 1200)
84
- return () => window.clearTimeout(timer)
85
- }, [clientId, gis])
86
-
87
- if (!clientId) return null
88
-
89
- const showOAuth = gis !== "ready"
90
- const showCredential = gis !== "fallback"
91
-
92
- const reportError = (message: string) => {
93
- setError(message)
94
- onError?.(message)
95
- }
96
-
97
- return (
98
- <GoogleAuthProvider clientId={clientId}>
99
- <GoogleIdentityServicesScript />
100
- {error ? (
101
- <p className="mb-3 text-sm text-brand-sale" role="alert">
102
- {error}
103
- </p>
104
- ) : null}
105
- <div className="google-signin-section" data-gis={gis}>
106
- {showCredential ? (
107
- <GoogleCredentialButton
108
- handlers={handlers}
109
- countryCode={countryCode}
110
- defaultCountryCode={defaultCountryCode}
111
- className={credentialButtonClassName}
112
- onError={(msg) => {
113
- setGis("fallback")
114
- reportError(msg)
115
- }}
116
- />
117
- ) : null}
118
- {showOAuth ? (
119
- <GoogleLoginButton
120
- countryCode={countryCode}
121
- defaultCountryCode={defaultCountryCode}
122
- className={oauthButtonClassName}
123
- initiateAuth={initiateGoogleAuth}
124
- />
125
- ) : null}
126
- {enableOneTap ? (
127
- <GoogleOneTapLogin
128
- handlers={handlers}
129
- countryCode={countryCode}
130
- defaultCountryCode={defaultCountryCode}
131
- useFedcmForPrompt={true}
132
- onError={(msg) => {
133
- if (process.env.NODE_ENV === "development") {
134
- console.info("[One Tap]", msg)
135
- }
136
- }}
137
- />
138
- ) : null}
139
- </div>
140
- </GoogleAuthProvider>
141
- )
142
- }
1
+ "use client"
2
+
3
+ import { useEffect, useState, type ReactNode } from "react"
4
+ import { GoogleAuthProvider } from "@pradip1995/commerce-auth/components/google-oauth-provider"
5
+ import { GoogleLoginButton } from "@pradip1995/commerce-auth/components/google-login"
6
+ import { initiateGoogleAuth } from "./auth-server"
7
+
8
+ /** commerce-auth GoogleAuthProvider wraps GoogleOAuthProvider only after mount; defer UI until then. */
9
+ function DeferGoogleOAuthUi({ children }: { children: ReactNode }) {
10
+ const [ready, setReady] = useState(false)
11
+ useEffect(() => {
12
+ setReady(true)
13
+ }, [])
14
+ if (!ready) return null
15
+ return <>{children}</>
16
+ }
17
+
18
+ /**
19
+ * Google Sign-In uses Medusa's authorization-code redirect.
20
+ * The GIS credential button returns an ID token, which @medusajs/auth-google rejects.
21
+ */
22
+ export function GoogleSignInSection({
23
+ countryCode,
24
+ defaultCountryCode = "in",
25
+ credentialButtonClassName,
26
+ oauthButtonClassName,
27
+ onError,
28
+ }: {
29
+ countryCode: string
30
+ defaultCountryCode?: string
31
+ enableOneTap?: boolean
32
+ credentialButtonClassName?: string
33
+ oauthButtonClassName?: string
34
+ onError?: (message: string) => void
35
+ }) {
36
+ const clientId = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID?.trim()
37
+ const [error, setError] = useState<string | null>(null)
38
+
39
+ if (!clientId) return null
40
+
41
+ return (
42
+ <GoogleAuthProvider clientId={clientId}>
43
+ <DeferGoogleOAuthUi>
44
+ {error ? (
45
+ <p className="mb-3 text-sm text-brand-sale" role="alert">
46
+ {error}
47
+ </p>
48
+ ) : null}
49
+ <div className="google-signin-section" data-gis="oauth">
50
+ <GoogleLoginButton
51
+ countryCode={countryCode}
52
+ defaultCountryCode={defaultCountryCode}
53
+ className={oauthButtonClassName || credentialButtonClassName}
54
+ initiateAuth={async (countryCode?: string) => {
55
+ const result = await initiateGoogleAuth(countryCode)
56
+ if (result.error) {
57
+ setError(result.error)
58
+ onError?.(result.error)
59
+ }
60
+ return result
61
+ }}
62
+ />
63
+ </div>
64
+ </DeferGoogleOAuthUi>
65
+ </GoogleAuthProvider>
66
+ )
67
+ }