@hszrdm/create-commerce 1.17.0 → 1.20.0
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 +1 -1
- package/templates/backend/.env.example +19 -24
- package/templates/backend/medusa-config.ts +14 -1
- package/templates/backend/package.json +1 -1
- package/templates/backend/scripts/core-backup.mjs +3 -1
- package/templates/backend/scripts/core-restore.mjs +17 -2
- package/templates/backend/scripts/lib/core-backup-common.mjs +32 -0
- package/templates/backend/src/scripts/core-init.ts +0 -5
- package/templates/storefront/package.json +3 -1
- package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +2 -2
- package/templates/storefront/src/app/layout.tsx +6 -0
- package/templates/storefront/src/components/account-access-gate.tsx +88 -0
- package/templates/storefront/src/components/account-dashboard.tsx +112 -24
- package/templates/storefront/src/components/account-verification-panel.tsx +145 -0
- package/templates/storefront/src/components/address-street-fields.tsx +47 -0
- package/templates/storefront/src/components/checkout-flow.tsx +132 -34
- package/templates/storefront/src/components/product-card.tsx +2 -1
- package/templates/storefront/src/lib/core/account.ts +49 -8
- package/templates/storefront/src/lib/core/checkout-addresses.ts +14 -6
- package/templates/storefront/src/lib/core/checkout-feedback-state.ts +15 -0
- package/templates/storefront/src/lib/core/checkout.ts +18 -19
- package/templates/storefront/src/lib/core/commerce.ts +11 -0
- package/templates/storefront/src/lib/core/structured-address.ts +92 -0
- package/templates/storefront/src/lib/core/use-checkout-feedback.ts +53 -0
- package/templates/storefront/tests/account-verification.test.mjs +40 -0
- package/templates/storefront/tests/checkout-addresses.test.mjs +59 -0
- package/templates/storefront/tests/checkout-feedback.test.mjs +27 -0
- package/templates/storefront/tests/product-image.test.mjs +31 -0
- package/templates/storefront/tsconfig.json +1 -0
package/package.json
CHANGED
|
@@ -271,33 +271,35 @@ SHIPPING_STATUS_SYNC_BATCH_SIZE=100
|
|
|
271
271
|
# Prefer Admin -> Settings -> Integrációk.
|
|
272
272
|
# -----------------------------------------------------------------------------
|
|
273
273
|
FOXPOST_ENABLED=false
|
|
274
|
-
#
|
|
274
|
+
# FOXPOST transport: operator-owned ENV only, never editable in Admin.
|
|
275
|
+
# A blank FOXPOST_SANDBOX follows APP_ENV (production=false, other=true).
|
|
275
276
|
# Egyedi környezetben itt felülírható.
|
|
276
277
|
FOXPOST_API_URL=
|
|
277
278
|
FOXPOST_API_USERNAME=
|
|
278
279
|
FOXPOST_API_PASSWORD=
|
|
279
280
|
FOXPOST_API_KEY=
|
|
280
|
-
FOXPOST_SANDBOX=
|
|
281
|
+
FOXPOST_SANDBOX=
|
|
281
282
|
# Fixed FOXPOST parcel size sent during Create Fulfillment (XS/S/M/L/XL); default M.
|
|
282
283
|
FOXPOST_PACKAGE_SIZE=M
|
|
283
284
|
FOXPOST_LOCKER_FEED_URL=https://cdn.foxpost.hu/foxplus.json
|
|
284
|
-
FOXPOST_LOCKER_PRICE_HUF=1290
|
|
285
|
-
FOXPOST_HOME_DELIVERY_PRICE_HUF=1990
|
|
286
|
-
FOXPOST_FREE_SHIPPING_THRESHOLD_HUF=
|
|
287
285
|
FOXPOST_TIMEOUT_MS=10000
|
|
288
286
|
|
|
289
287
|
GLS_ENABLED=false
|
|
290
|
-
GLS_API_URL=https://api.
|
|
288
|
+
GLS_API_URL=https://api.mygls.hu
|
|
291
289
|
GLS_USERNAME=
|
|
292
290
|
GLS_PASSWORD=
|
|
293
291
|
GLS_CLIENT_NUMBER=
|
|
294
|
-
GLS_SANDBOX=
|
|
292
|
+
GLS_SANDBOX=false
|
|
295
293
|
GLS_DELIVERY_POINTS_URL=https://map.gls-hungary.com/data/deliveryPoints/hu.json
|
|
296
294
|
GLS_POINT_PRICE_HUF=1490
|
|
297
295
|
GLS_HOME_DELIVERY_PRICE_HUF=1990
|
|
298
296
|
GLS_FREE_SHIPPING_THRESHOLD_HUF=
|
|
299
297
|
GLS_TIMEOUT_MS=15000
|
|
300
298
|
GLS_PRINTER_TYPE=A4_2x2
|
|
299
|
+
# Optional absolute PRIVATE directory for original GLS PDF labels.
|
|
300
|
+
# Default: a non-public sibling of FILE_UPLOAD_DIR (.hszrdm-gls-private-labels).
|
|
301
|
+
# Must survive deploy and be included in filesystem backups. Never expose via /static.
|
|
302
|
+
GLS_PRIVATE_LABEL_DIR=
|
|
301
303
|
GLS_WEBSHOP_ENGINE=HSZRDM Commerce
|
|
302
304
|
GLS_PICKUP_NAME=Example Store
|
|
303
305
|
GLS_PICKUP_STREET=
|
|
@@ -316,9 +318,9 @@ PACKETA_API_KEY=
|
|
|
316
318
|
PACKETA_API_PASSWORD=
|
|
317
319
|
PACKETA_SENDER_INDICATION=
|
|
318
320
|
PACKETA_HOME_CARRIER_ID=
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
321
|
+
# Optional JSON map of destination country to contracted Packeta HOME carrier ID.
|
|
322
|
+
PACKETA_HOME_CARRIER_IDS=
|
|
323
|
+
# Technical, fixed at server deployment; not mutable from Admin.
|
|
322
324
|
PACKETA_TIMEOUT_MS=15000
|
|
323
325
|
PACKETA_DEFAULT_WEIGHT_KG=1
|
|
324
326
|
PACKETA_LABEL_FORMAT=A6 on A6
|
|
@@ -327,8 +329,10 @@ PACKETA_LANGUAGE=hu
|
|
|
327
329
|
# raw body and timestamp are mandatory. Rotate separately from other webhook secrets.
|
|
328
330
|
PACKETA_WEBHOOK_SIGNING_KEY=
|
|
329
331
|
|
|
332
|
+
# DPD technical settings are deployment-controlled. Blank sandbox follows APP_ENV.
|
|
333
|
+
# Shipping prices are fixed Medusa Shipping Options, not DPD ENV fields.
|
|
330
334
|
DPD_ENABLED=false
|
|
331
|
-
DPD_SANDBOX=
|
|
335
|
+
DPD_SANDBOX=
|
|
332
336
|
DPD_API_URL=
|
|
333
337
|
DPD_TOKEN=
|
|
334
338
|
DPD_BU_CODE=
|
|
@@ -342,9 +346,6 @@ DPD_PUDO_LOCATOR_URL=
|
|
|
342
346
|
DPD_PUDO_DELIS_ID=
|
|
343
347
|
DPD_PUDO_PASSWORD=
|
|
344
348
|
DPD_PUDO_MESSAGE_LANGUAGE=en_US
|
|
345
|
-
DPD_POINT_PRICE_HUF=1490
|
|
346
|
-
DPD_HOME_DELIVERY_PRICE_HUF=1990
|
|
347
|
-
DPD_FREE_SHIPPING_THRESHOLD_HUF=
|
|
348
349
|
DPD_TIMEOUT_MS=15000
|
|
349
350
|
DPD_DEFAULT_WEIGHT_KG=1
|
|
350
351
|
DPD_LABEL_SIZE=A6
|
|
@@ -394,18 +395,12 @@ MPL_TRACKING_ACCOUNT_CODE=
|
|
|
394
395
|
MPL_PUSH_READ_WINDOW_MS=8000
|
|
395
396
|
MPL_TRACKING_LANGUAGE=hu
|
|
396
397
|
|
|
397
|
-
|
|
398
|
-
|
|
398
|
+
# Csomagpiac technical transport is operator-owned; credentials, sender ID,
|
|
399
|
+
# label format and service profiles are configured in the encrypted Admin DB.
|
|
400
|
+
# Leave CSOMAGPIAC_LIVE unset to follow APP_ENV automatically.
|
|
401
|
+
CSOMAGPIAC_LIVE=
|
|
399
402
|
CSOMAGPIAC_API_URL=
|
|
400
|
-
CSOMAGPIAC_TOKEN=
|
|
401
|
-
CSOMAGPIAC_USERNAME=
|
|
402
|
-
CSOMAGPIAC_PASSWORD=
|
|
403
|
-
CSOMAGPIAC_PICKUP_POINT_ID=
|
|
404
|
-
CSOMAGPIAC_PRICE_HUF=1990
|
|
405
|
-
CSOMAGPIAC_FREE_SHIPPING_THRESHOLD_HUF=
|
|
406
403
|
CSOMAGPIAC_TIMEOUT_MS=15000
|
|
407
|
-
CSOMAGPIAC_DEFAULT_WEIGHT_KG=1
|
|
408
|
-
CSOMAGPIAC_LABEL_FORMAT=A4
|
|
409
404
|
|
|
410
405
|
# -----------------------------------------------------------------------------
|
|
411
406
|
# Product feeds / trust widgets - optional
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { basename, dirname, resolve } from "node:path"
|
|
1
2
|
import { loadEnv } from "@medusajs/framework/utils"
|
|
2
3
|
import { createHszrdmCommerceConfig } from "@hszrdm/core/config"
|
|
3
4
|
|
|
@@ -6,7 +7,19 @@ const envFile =
|
|
|
6
7
|
? "test"
|
|
7
8
|
: process.env.NODE_ENV || "development"
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
// In a production build, Medusa starts inside backend/.medusa/server.
|
|
11
|
+
// Read the original backend env file, not a generated directory that is
|
|
12
|
+
// replaced on every build. Development and test working directories are kept.
|
|
13
|
+
const cwd = process.cwd()
|
|
14
|
+
const runningFromBuiltServer =
|
|
15
|
+
basename(cwd) === "server" &&
|
|
16
|
+
basename(dirname(cwd)) === ".medusa"
|
|
17
|
+
|
|
18
|
+
const envRoot = runningFromBuiltServer
|
|
19
|
+
? resolve(cwd, "../..")
|
|
20
|
+
: cwd
|
|
21
|
+
|
|
22
|
+
loadEnv(envFile, envRoot)
|
|
10
23
|
|
|
11
24
|
const baseConfig = createHszrdmCommerceConfig()
|
|
12
25
|
const configuredPlugins = (
|
|
@@ -122,7 +122,9 @@ function runBackup() {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
const copiedFiles = []
|
|
125
|
-
|
|
125
|
+
// The archived GLS PDF scope must follow the database actually being
|
|
126
|
+
// backed up, including an explicit --database-url override.
|
|
127
|
+
for (const item of backupFileSources(projectDir, { ...env, DATABASE_URL: databaseUrl })) {
|
|
126
128
|
console.log(`- ${item.key} mentése...`)
|
|
127
129
|
const target = copyBackupSource(bundleDir, item)
|
|
128
130
|
copiedFiles.push({ ...item, target })
|
|
@@ -13,6 +13,7 @@ import process from "node:process"
|
|
|
13
13
|
|
|
14
14
|
import {
|
|
15
15
|
backendProjectDir,
|
|
16
|
+
glsPrivateLabelDirectory,
|
|
16
17
|
integrationSnapshotPath,
|
|
17
18
|
loadRuntimeEnv,
|
|
18
19
|
pgEnvironment,
|
|
@@ -65,7 +66,8 @@ if (["postgres", "template0", "template1"].includes(pg.database.toLowerCase()) |
|
|
|
65
66
|
"Destruktív restore megtagadva. Add meg a pontos céladatbázist: --confirm-database=" + pg.database,
|
|
66
67
|
)
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
+
const restoreEnv = { ...env, DATABASE_URL: databaseUrl }
|
|
70
|
+
assertRestoreTargets({ projectDir, bundleDir, env: restoreEnv, overwrite: Boolean(args["overwrite-files"]) })
|
|
69
71
|
|
|
70
72
|
const dumpPath = join(bundleDir, "database.dump")
|
|
71
73
|
console.log("\n- PostgreSQL visszaállítása (--clean --if-exists)...")
|
|
@@ -94,7 +96,7 @@ if (existsSync(portableSource)) {
|
|
|
94
96
|
console.log(" (szándékosan nincs automatikusan bemásolva a production .env-be)")
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
restoreFiles({ projectDir, bundleDir, env, overwrite: Boolean(args["overwrite-files"]) })
|
|
99
|
+
restoreFiles({ projectDir, bundleDir, env: restoreEnv, overwrite: Boolean(args["overwrite-files"]) })
|
|
98
100
|
|
|
99
101
|
if (args.migrate) {
|
|
100
102
|
console.log("- Core migrációk futtatása...")
|
|
@@ -124,6 +126,12 @@ function assertRestoreTargets({ projectDir, bundleDir, env, overwrite }) {
|
|
|
124
126
|
}
|
|
125
127
|
checks.push([uploadSource, uploadTarget])
|
|
126
128
|
}
|
|
129
|
+
const glsSource = join(bundleDir, "files", "gls-private-labels")
|
|
130
|
+
if (existsSync(glsSource)) {
|
|
131
|
+
const glsTarget = glsPrivateLabelDirectory(env)
|
|
132
|
+
if (!glsTarget) throw new Error("A GLS privát PDF címkék visszaállításához abszolút FILE_UPLOAD_DIR vagy GLS_PRIVATE_LABEL_DIR és DATABASE_URL szükséges.")
|
|
133
|
+
checks.push([glsSource, glsTarget])
|
|
134
|
+
}
|
|
127
135
|
for (const [source, target] of checks) {
|
|
128
136
|
if (existsSync(source) && existsSync(target) && !overwrite) {
|
|
129
137
|
throw new Error("A restore felülírna egy meglévő útvonalat: " + target +
|
|
@@ -158,6 +166,13 @@ function restoreFiles({ projectDir, bundleDir, env, overwrite }) {
|
|
|
158
166
|
copyWithGuard(uploadSource, configured, overwrite)
|
|
159
167
|
console.log(`- FILE_UPLOAD_DIR visszaállítva: ${configured}`)
|
|
160
168
|
}
|
|
169
|
+
const glsSource = join(bundleDir, "files", "gls-private-labels")
|
|
170
|
+
if (existsSync(glsSource)) {
|
|
171
|
+
const target = glsPrivateLabelDirectory(env)
|
|
172
|
+
if (!target) throw new Error("Nem található privát GLS PDF tárolási célkönyvtár.")
|
|
173
|
+
copyWithGuard(glsSource, target, overwrite)
|
|
174
|
+
console.log("- Privát GLS PDF címkék visszaállítva a célkörnyezet elkülönített tárolójába.")
|
|
175
|
+
}
|
|
161
176
|
}
|
|
162
177
|
|
|
163
178
|
function copyWithGuard(source, target, overwrite) {
|
|
@@ -148,6 +148,33 @@ export function integrationSnapshotPath(projectDir, env) {
|
|
|
148
148
|
return join(backendDir, ".core", "integration-settings.enc")
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
/** Keep original MyGLS PDF labels alongside DB-scoped, non-public assets. */
|
|
152
|
+
export function glsPrivateLabelDirectory(env) {
|
|
153
|
+
const database = String(env.DATABASE_URL || "").trim()
|
|
154
|
+
if (!database) return null
|
|
155
|
+
const explicit = String(env.GLS_PRIVATE_LABEL_DIR || "").trim()
|
|
156
|
+
const uploads = String(env.FILE_UPLOAD_DIR || "").trim()
|
|
157
|
+
let base
|
|
158
|
+
if (explicit && isAbsolute(explicit) && resolve(explicit) !== "/") {
|
|
159
|
+
base = resolve(explicit)
|
|
160
|
+
} else if (!explicit && uploads && isAbsolute(uploads) && resolve(uploads) !== "/") {
|
|
161
|
+
base = join(dirname(resolve(uploads)), ".hszrdm-gls-private-labels")
|
|
162
|
+
} else {
|
|
163
|
+
return null
|
|
164
|
+
}
|
|
165
|
+
const url = new URL(database)
|
|
166
|
+
const appEnv = String(env.APP_ENV || "").trim() || (env.NODE_ENV === "production" ? "production" : "development")
|
|
167
|
+
// Same stable scope contract as private-label-store.ts. The connection
|
|
168
|
+
// host/port/user/credentials are not part of the PDF archive identity.
|
|
169
|
+
if (!url.pathname || url.pathname === "/") {
|
|
170
|
+
throw new Error("A GLS privát címketárolóhoz adatbázisnév szükséges.")
|
|
171
|
+
}
|
|
172
|
+
const scope = createHash("sha256")
|
|
173
|
+
.update(JSON.stringify(["gls-pdf-v2", appEnv, decodeURIComponent(url.pathname)]))
|
|
174
|
+
.digest("hex").slice(0, 24)
|
|
175
|
+
return join(base, scope)
|
|
176
|
+
}
|
|
177
|
+
|
|
151
178
|
export function backupFileSources(projectDir, env) {
|
|
152
179
|
const sources = []
|
|
153
180
|
const backendDir = backendProjectDir(projectDir)
|
|
@@ -165,6 +192,10 @@ export function backupFileSources(projectDir, env) {
|
|
|
165
192
|
if (configuredUpload && isAbsolute(configuredUpload) && existsSync(configuredUpload)) {
|
|
166
193
|
sources.push({ key: "file_upload_dir", source: configuredUpload, relative: "files/file-upload-dir" })
|
|
167
194
|
}
|
|
195
|
+
const glsLabels = glsPrivateLabelDirectory(env)
|
|
196
|
+
if (glsLabels && existsSync(glsLabels)) {
|
|
197
|
+
sources.push({ key: "gls_private_labels", source: glsLabels, relative: "files/gls-private-labels" })
|
|
198
|
+
}
|
|
168
199
|
return sources
|
|
169
200
|
}
|
|
170
201
|
|
|
@@ -204,6 +235,7 @@ const ARTIFACT_KINDS = new Map([
|
|
|
204
235
|
["files/integration-settings.enc", "file"],
|
|
205
236
|
["files/local-static", "directory"],
|
|
206
237
|
["files/file-upload-dir", "directory"],
|
|
238
|
+
["files/gls-private-labels", "directory"],
|
|
207
239
|
])
|
|
208
240
|
const REQUIRED_ARTIFACTS = ["database.dump", "portable-config.json", "portable-config.env"]
|
|
209
241
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ExecArgs } from "@medusajs/framework/types"
|
|
2
2
|
import coreInit from "@hszrdm/core/scripts/core-init"
|
|
3
3
|
import ensureLocales from "@hszrdm/core/scripts/ensure-locales"
|
|
4
|
-
import ensureShipping from "@hszrdm/core/scripts/ensure-shipping"
|
|
5
4
|
import { normalizeMedusaExecArgs } from "@hszrdm/core/scripts/exec-args"
|
|
6
5
|
|
|
7
6
|
export default async function runCoreInit(params: ExecArgs) {
|
|
@@ -28,8 +27,4 @@ export default async function runCoreInit(params: ExecArgs) {
|
|
|
28
27
|
args: [],
|
|
29
28
|
})
|
|
30
29
|
|
|
31
|
-
await ensureShipping({
|
|
32
|
-
...params,
|
|
33
|
-
args: [],
|
|
34
|
-
})
|
|
35
30
|
}
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
"test:stripe": "node --experimental-strip-types --test tests/stripe-checkout-phase.test.mjs",
|
|
15
15
|
"test:company-tax": "node --experimental-strip-types --test tests/company-tax.test.mjs",
|
|
16
16
|
"test:ga4": "node --experimental-strip-types --test tests/ga4-bootstrap.test.mjs",
|
|
17
|
-
"test:seo": "node --experimental-strip-types --test tests/technical-seo.test.mjs"
|
|
17
|
+
"test:seo": "node --experimental-strip-types --test tests/technical-seo.test.mjs",
|
|
18
|
+
"test:account-verification": "node --test tests/account-verification.test.mjs",
|
|
19
|
+
"test:product-images": "node --experimental-strip-types --test tests/product-image.test.mjs"
|
|
18
20
|
},
|
|
19
21
|
"dependencies": {
|
|
20
22
|
"@stripe/react-stripe-js": "7.0.0",
|
|
@@ -11,7 +11,7 @@ import { WishlistButton } from "@/components/wishlist-button"
|
|
|
11
11
|
import { getCoreConfig } from "@/lib/core/client"
|
|
12
12
|
import { checkoutApi } from "@/lib/core/checkout"
|
|
13
13
|
import { getProductByHandle } from "@/lib/core/catalog"
|
|
14
|
-
import { asRecords, productVariantCurrency, productVariantPriceBreakdown, stringValue } from "@/lib/core/commerce"
|
|
14
|
+
import { asRecords, productImageUrl, productVariantCurrency, productVariantPriceBreakdown, stringValue } from "@/lib/core/commerce"
|
|
15
15
|
import { googleAdsRemarketingItemFromProduct } from "@/lib/core/google-ads"
|
|
16
16
|
import { metadataFromCore, serializeJsonLd, structuredDataForEntity } from "@/lib/core/seo"
|
|
17
17
|
import { ecommerceItemFromProduct } from "@/lib/core/tracking"
|
|
@@ -49,7 +49,7 @@ export default async function ProductPage({ params }: { params: Promise<{ countr
|
|
|
49
49
|
const images = asRecords(product.images)
|
|
50
50
|
const productId = stringValue(product.id)
|
|
51
51
|
const title = stringValue(product.title)
|
|
52
|
-
const thumbnail =
|
|
52
|
+
const thumbnail = productImageUrl(product)
|
|
53
53
|
const formatLocale = locale === "en" ? "en-US" : "hu-HU"
|
|
54
54
|
const galleryImages = [
|
|
55
55
|
...(thumbnail ? [{ id: "thumbnail", url: thumbnail, alt: title }] : []),
|
|
@@ -8,6 +8,7 @@ import { AnalyticsGate } from "@/components/analytics"
|
|
|
8
8
|
import { ArukeresoBacklink } from "@/components/arukereso-backlink"
|
|
9
9
|
import { ArukeresoTrustedShopWidget } from "@/components/arukereso-trusted-shop-widget"
|
|
10
10
|
import { CartProvider } from "@/components/cart-provider"
|
|
11
|
+
import { AccountAccessGate } from "@/components/account-access-gate"
|
|
11
12
|
import { ConsentBanner } from "@/components/consent-banner"
|
|
12
13
|
import { CustomerCartResumeGate } from "@/components/customer-cart-resume-gate"
|
|
13
14
|
import { GoogleAdsCartRemarketing } from "@/components/google-ads-cart-remarketing"
|
|
@@ -70,6 +71,10 @@ export default async function RootLayout({ children }: Readonly<{ children: Reac
|
|
|
70
71
|
<AccessibilityPreferencesProvider>
|
|
71
72
|
<ToastProvider locale={locale}>
|
|
72
73
|
<CartProvider config={config}>
|
|
74
|
+
<AccountAccessGate
|
|
75
|
+
config={config}
|
|
76
|
+
restrictedChildren={<main id="main-content" className="shell main" tabIndex={-1}>{children}</main>}
|
|
77
|
+
>
|
|
73
78
|
<GoogleAdsCartRemarketing googleAds={config.marketing.google_ads} />
|
|
74
79
|
<a className="skip-link" href="#main-content">
|
|
75
80
|
{en ? "Skip to content" : "Ugrás a tartalomhoz"}
|
|
@@ -107,6 +112,7 @@ export default async function RootLayout({ children }: Readonly<{ children: Reac
|
|
|
107
112
|
{fogyasztobarat.enabled && fogyasztobarat.placement === "global" ? (
|
|
108
113
|
<FogyasztobaratEmbed embed={fogyasztobarat} />
|
|
109
114
|
) : null}
|
|
115
|
+
</AccountAccessGate>
|
|
110
116
|
</CartProvider>
|
|
111
117
|
</ToastProvider>
|
|
112
118
|
</AccessibilityPreferencesProvider>
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react"
|
|
4
|
+
import { usePathname, useRouter } from "next/navigation"
|
|
5
|
+
import {
|
|
6
|
+
ACCOUNT_AUTH_CHANGED_EVENT,
|
|
7
|
+
accountApi,
|
|
8
|
+
isAccountEmailVerified,
|
|
9
|
+
} from "@/lib/core/account"
|
|
10
|
+
import { CoreApiError } from "@/lib/core/client"
|
|
11
|
+
import type { CoreConfig } from "@/lib/core/types"
|
|
12
|
+
|
|
13
|
+
type AccountAccessState = "guest" | "checking" | "verified" | "unverified" | "error"
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Public pages stay SSR-rendered for search engines. Once hydrated, a signed-in
|
|
17
|
+
* unverified customer is redirected to the profile-only verification view.
|
|
18
|
+
* Authorization itself is enforced on the Core Store API, never by this UI.
|
|
19
|
+
*/
|
|
20
|
+
export function AccountAccessGate({
|
|
21
|
+
config,
|
|
22
|
+
children,
|
|
23
|
+
restrictedChildren,
|
|
24
|
+
}: {
|
|
25
|
+
config: CoreConfig
|
|
26
|
+
children: ReactNode
|
|
27
|
+
restrictedChildren: ReactNode
|
|
28
|
+
}) {
|
|
29
|
+
const api = useMemo(() => accountApi(config), [config])
|
|
30
|
+
const pathname = usePathname()
|
|
31
|
+
const router = useRouter()
|
|
32
|
+
const [state, setState] = useState<AccountAccessState>("guest")
|
|
33
|
+
const requestId = useRef(0)
|
|
34
|
+
|
|
35
|
+
const refresh = useCallback(async () => {
|
|
36
|
+
const current = ++requestId.current
|
|
37
|
+
try {
|
|
38
|
+
const { customer } = await api.profile()
|
|
39
|
+
if (requestId.current !== current) return
|
|
40
|
+
setState(isAccountEmailVerified(customer) ? "verified" : "unverified")
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (requestId.current !== current) return
|
|
43
|
+
if (error instanceof CoreApiError && error.status === 401) {
|
|
44
|
+
setState("guest")
|
|
45
|
+
} else {
|
|
46
|
+
setState("error")
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}, [api])
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
void refresh()
|
|
53
|
+
const authChanged = () => {
|
|
54
|
+
setState("checking")
|
|
55
|
+
void refresh()
|
|
56
|
+
}
|
|
57
|
+
window.addEventListener(ACCOUNT_AUTH_CHANGED_EVENT, authChanged)
|
|
58
|
+
return () => {
|
|
59
|
+
requestId.current++
|
|
60
|
+
window.removeEventListener(ACCOUNT_AUTH_CHANGED_EVENT, authChanged)
|
|
61
|
+
}
|
|
62
|
+
}, [refresh])
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (state === "unverified" && pathname !== "/account") {
|
|
66
|
+
router.replace("/account")
|
|
67
|
+
}
|
|
68
|
+
}, [state, pathname, router])
|
|
69
|
+
|
|
70
|
+
if (state === "checking" || (state === "unverified" && pathname !== "/account")) {
|
|
71
|
+
return <main className="shell main" role="status">A fiók ellenőrzése…</main>
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (state === "error") {
|
|
75
|
+
return (
|
|
76
|
+
<main className="shell main">
|
|
77
|
+
<section className="panel stack">
|
|
78
|
+
<h1>A fiók állapota nem ellenőrizhető</h1>
|
|
79
|
+
<p>Próbáld meg újra. A megerősítés ellenőrzése nélkül a fiók nem használható.</p>
|
|
80
|
+
<button className="button" type="button" onClick={() => { setState("checking"); void refresh() }}>Újrapróbálkozás</button>
|
|
81
|
+
</section>
|
|
82
|
+
</main>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (state === "unverified") return <>{restrictedChildren}</>
|
|
87
|
+
return <>{children}</>
|
|
88
|
+
}
|