@pradip1995/segment-login-template 0.5.24 → 0.5.25

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.24",
3
+ "version": "0.5.25",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,56 +1,27 @@
1
1
  "use client"
2
2
 
3
- import { useEffect, useMemo, useState } from "react"
3
+ import { useEffect, useState, type ReactNode } from "react"
4
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
5
  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"
6
+ import { initiateGoogleAuth } from "./auth-server"
14
7
 
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) {
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)
20
11
  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
- }
12
+ setReady(true)
13
+ }, [])
14
+ if (!ready) return null
15
+ return <>{children}</>
44
16
  }
45
17
 
46
18
  /**
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).
19
+ * Google Sign-In uses Medusa's authorization-code redirect.
20
+ * The GIS credential button returns an ID token, which @medusajs/auth-google rejects.
49
21
  */
50
22
  export function GoogleSignInSection({
51
23
  countryCode,
52
24
  defaultCountryCode = "in",
53
- enableOneTap = true,
54
25
  credentialButtonClassName,
55
26
  oauthButtonClassName,
56
27
  onError,
@@ -63,80 +34,34 @@ export function GoogleSignInSection({
63
34
  onError?: (message: string) => void
64
35
  }) {
65
36
  const clientId = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID?.trim()
66
- const [gis, setGis] = useState<GisUiState>("loading")
67
37
  const [error, setError] = useState<string | null>(null)
68
38
 
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
39
  if (!clientId) return null
88
40
 
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
41
  return (
98
42
  <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
- />
43
+ <DeferGoogleOAuthUi>
44
+ {error ? (
45
+ <p className="mb-3 text-sm text-brand-sale" role="alert">
46
+ {error}
47
+ </p>
117
48
  ) : null}
118
- {showOAuth ? (
49
+ <div className="google-signin-section" data-gis="oauth">
119
50
  <GoogleLoginButton
120
51
  countryCode={countryCode}
121
52
  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)
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)
135
59
  }
60
+ return result
136
61
  }}
137
62
  />
138
- ) : null}
139
- </div>
63
+ </div>
64
+ </DeferGoogleOAuthUi>
140
65
  </GoogleAuthProvider>
141
66
  )
142
67
  }