@open-mercato/core 0.11.1-develop.8545.1.dd603570fd → 0.11.1-develop.8549.1.bd34c91190
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/.turbo/turbo-build.log +1 -1
- package/dist/modules/customer_accounts/api/admin/users/[id]/verify-email.js +10 -30
- package/dist/modules/customer_accounts/api/admin/users/[id]/verify-email.js.map +2 -2
- package/dist/modules/customer_accounts/api/email/verify.js +11 -10
- package/dist/modules/customer_accounts/api/email/verify.js.map +2 -2
- package/dist/modules/customer_accounts/api/magic-link/verify.js +9 -8
- package/dist/modules/customer_accounts/api/magic-link/verify.js.map +2 -2
- package/dist/modules/customer_accounts/api/password/reset-confirm.js +13 -16
- package/dist/modules/customer_accounts/api/password/reset-confirm.js.map +2 -2
- package/dist/modules/customer_accounts/api/signup.js +33 -19
- package/dist/modules/customer_accounts/api/signup.js.map +3 -3
- package/dist/modules/customer_accounts/data/validators.js +3 -2
- package/dist/modules/customer_accounts/data/validators.js.map +2 -2
- package/dist/modules/customer_accounts/lib/customerAuth.js +11 -10
- package/dist/modules/customer_accounts/lib/customerAuth.js.map +2 -2
- package/dist/modules/customer_accounts/lib/customerAuthServer.js +7 -7
- package/dist/modules/customer_accounts/lib/customerAuthServer.js.map +2 -2
- package/dist/modules/customer_accounts/lib/pendingSignup.js +16 -0
- package/dist/modules/customer_accounts/lib/pendingSignup.js.map +7 -0
- package/dist/modules/customer_accounts/lib/verifyCustomerEmail.js +50 -0
- package/dist/modules/customer_accounts/lib/verifyCustomerEmail.js.map +7 -0
- package/dist/modules/customer_accounts/services/customerInvitationService.js +15 -1
- package/dist/modules/customer_accounts/services/customerInvitationService.js.map +2 -2
- package/dist/modules/customer_accounts/services/customerTokenService.js +13 -13
- package/dist/modules/customer_accounts/services/customerTokenService.js.map +2 -2
- package/dist/modules/customer_accounts/services/customerUserService.js +1 -1
- package/dist/modules/customer_accounts/services/customerUserService.js.map +2 -2
- package/dist/modules/customer_accounts/subscribers/autoLinkCrm.js +44 -51
- package/dist/modules/customer_accounts/subscribers/autoLinkCrm.js.map +2 -2
- package/dist/modules/customer_accounts/subscribers/autoLinkCrmOnVerification.js +12 -0
- package/dist/modules/customer_accounts/subscribers/autoLinkCrmOnVerification.js.map +7 -0
- package/dist/modules/customer_accounts/subscribers/autoLinkCrmReverse.js +3 -1
- package/dist/modules/customer_accounts/subscribers/autoLinkCrmReverse.js.map +2 -2
- package/dist/modules/customer_accounts/workers/cleanupExpiredTokens.js +6 -0
- package/dist/modules/customer_accounts/workers/cleanupExpiredTokens.js.map +2 -2
- package/dist/modules/portal/frontend/[orgSlug]/portal/PasswordForm.js +127 -0
- package/dist/modules/portal/frontend/[orgSlug]/portal/PasswordForm.js.map +7 -0
- package/dist/modules/portal/frontend/[orgSlug]/portal/reset-password/page.js +10 -122
- package/dist/modules/portal/frontend/[orgSlug]/portal/reset-password/page.js.map +2 -2
- package/dist/modules/portal/frontend/[orgSlug]/portal/signup/page.js +2 -11
- package/dist/modules/portal/frontend/[orgSlug]/portal/signup/page.js.map +2 -2
- package/dist/modules/portal/frontend/[orgSlug]/portal/verify/page.js +3 -61
- package/dist/modules/portal/frontend/[orgSlug]/portal/verify/page.js.map +2 -2
- package/package.json +7 -7
- package/src/modules/customer_accounts/api/admin/users/[id]/verify-email.ts +11 -33
- package/src/modules/customer_accounts/api/email/verify.ts +15 -11
- package/src/modules/customer_accounts/api/magic-link/verify.ts +9 -9
- package/src/modules/customer_accounts/api/password/reset-confirm.ts +13 -18
- package/src/modules/customer_accounts/api/signup.ts +36 -24
- package/src/modules/customer_accounts/data/validators.ts +2 -1
- package/src/modules/customer_accounts/lib/customerAuth.ts +12 -10
- package/src/modules/customer_accounts/lib/customerAuthServer.ts +7 -7
- package/src/modules/customer_accounts/lib/pendingSignup.ts +12 -0
- package/src/modules/customer_accounts/lib/verifyCustomerEmail.ts +57 -0
- package/src/modules/customer_accounts/services/customerInvitationService.ts +16 -1
- package/src/modules/customer_accounts/services/customerTokenService.ts +13 -13
- package/src/modules/customer_accounts/services/customerUserService.ts +2 -2
- package/src/modules/customer_accounts/subscribers/autoLinkCrm.ts +46 -78
- package/src/modules/customer_accounts/subscribers/autoLinkCrmOnVerification.ts +9 -0
- package/src/modules/customer_accounts/subscribers/autoLinkCrmReverse.ts +3 -1
- package/src/modules/customer_accounts/workers/cleanupExpiredTokens.ts +7 -0
- package/src/modules/portal/frontend/[orgSlug]/portal/PasswordForm.tsx +182 -0
- package/src/modules/portal/frontend/[orgSlug]/portal/reset-password/page.tsx +9 -165
- package/src/modules/portal/frontend/[orgSlug]/portal/signup/page.tsx +2 -12
- package/src/modules/portal/frontend/[orgSlug]/portal/verify/page.tsx +3 -89
- package/src/modules/portal/i18n/de.json +2 -1
- package/src/modules/portal/i18n/en.json +2 -1
- package/src/modules/portal/i18n/es.json +2 -1
- package/src/modules/portal/i18n/ko.json +2 -1
- package/src/modules/portal/i18n/pl.json +2 -1
|
@@ -1,132 +1,20 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx
|
|
3
|
-
import {
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
4
|
import { extensionPoints } from "@open-mercato/core/modules/portal/extension-points";
|
|
5
|
-
import { useSearchParams } from "next/navigation";
|
|
6
|
-
import Link from "next/link";
|
|
7
|
-
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
8
|
-
import { PasswordInput } from "@open-mercato/ui/primitives/password-input";
|
|
9
|
-
import { Label } from "@open-mercato/ui/primitives/label";
|
|
10
|
-
import { Button } from "@open-mercato/ui/primitives/button";
|
|
11
|
-
import { Alert, AlertDescription } from "@open-mercato/ui/primitives/alert";
|
|
12
|
-
import { EmptyState } from "@open-mercato/ui/primitives/empty-state";
|
|
13
|
-
import { SearchX } from "lucide-react";
|
|
14
|
-
import { Spinner } from "@open-mercato/ui/primitives/spinner";
|
|
15
|
-
import { apiCall } from "@open-mercato/ui/backend/utils/apiCall";
|
|
16
|
-
import { usePortalContext } from "@open-mercato/ui/portal/PortalContext";
|
|
17
5
|
import { InjectionSpot } from "@open-mercato/ui/backend/injection/InjectionSpot";
|
|
6
|
+
import { PortalPasswordForm } from "../PasswordForm.js";
|
|
18
7
|
function PortalResetPasswordPage({ params }) {
|
|
19
|
-
const t = useT();
|
|
20
8
|
const orgSlug = params.orgSlug;
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const [token, setToken] = useState(null);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
const tokenParam = searchParams.get("token");
|
|
31
|
-
if (!tokenParam) {
|
|
32
|
-
setError(t("portal.resetPassword.error.noToken", "Invalid or missing reset token."));
|
|
33
|
-
} else {
|
|
34
|
-
setToken(tokenParam);
|
|
9
|
+
const injectionContext = useMemo(() => ({ orgSlug }), [orgSlug]);
|
|
10
|
+
return /* @__PURE__ */ jsx(
|
|
11
|
+
PortalPasswordForm,
|
|
12
|
+
{
|
|
13
|
+
params,
|
|
14
|
+
beforeForm: /* @__PURE__ */ jsx(InjectionSpot, { spotId: extensionPoints.hosts.resetPasswordBefore.spotId, context: injectionContext }),
|
|
15
|
+
afterForm: /* @__PURE__ */ jsx(InjectionSpot, { spotId: extensionPoints.hosts.resetPasswordAfter.spotId, context: injectionContext })
|
|
35
16
|
}
|
|
36
|
-
}, [searchParams, t]);
|
|
37
|
-
const handleSubmit = useCallback(
|
|
38
|
-
async (event) => {
|
|
39
|
-
event.preventDefault();
|
|
40
|
-
setError(null);
|
|
41
|
-
if (!token) {
|
|
42
|
-
setError(t("portal.resetPassword.error.noToken", "Invalid or missing reset token."));
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (password !== confirmPassword) {
|
|
46
|
-
setError(t("portal.resetPassword.error.passwordMismatch", "Passwords do not match."));
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (password.length < 8) {
|
|
50
|
-
setError(t("portal.resetPassword.error.passwordTooShort", "Password must be at least 8 characters long."));
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
setSubmitting(true);
|
|
54
|
-
try {
|
|
55
|
-
const result = await apiCall("/api/customer_accounts/password/reset-confirm", {
|
|
56
|
-
method: "POST",
|
|
57
|
-
headers: { "Content-Type": "application/json" },
|
|
58
|
-
body: JSON.stringify({ token, password })
|
|
59
|
-
});
|
|
60
|
-
if (result.ok && result.result?.ok) {
|
|
61
|
-
setSuccess(true);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (result.status === 400) {
|
|
65
|
-
setError(t("portal.resetPassword.error.invalidToken", "Invalid or expired reset token."));
|
|
66
|
-
} else {
|
|
67
|
-
setError(result.result?.error || t("portal.resetPassword.error.generic", "Password reset failed. Please try again."));
|
|
68
|
-
}
|
|
69
|
-
} catch {
|
|
70
|
-
setError(t("portal.resetPassword.error.generic", "Password reset failed. Please try again."));
|
|
71
|
-
} finally {
|
|
72
|
-
setSubmitting(false);
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
[token, password, confirmPassword, t]
|
|
76
17
|
);
|
|
77
|
-
const injectionContext = useMemo(
|
|
78
|
-
() => ({ orgSlug }),
|
|
79
|
-
[orgSlug]
|
|
80
|
-
);
|
|
81
|
-
if (tenant.loading) {
|
|
82
|
-
return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-20", children: /* @__PURE__ */ jsx(Spinner, {}) });
|
|
83
|
-
}
|
|
84
|
-
if (tenant.error) {
|
|
85
|
-
return /* @__PURE__ */ jsx("div", { className: "mx-auto w-full max-w-md py-12", children: /* @__PURE__ */ jsx(
|
|
86
|
-
EmptyState,
|
|
87
|
-
{
|
|
88
|
-
variant: "subtle",
|
|
89
|
-
size: "lg",
|
|
90
|
-
icon: /* @__PURE__ */ jsx(SearchX, { className: "h-6 w-6", "aria-hidden": true }),
|
|
91
|
-
title: t("portal.org.invalid", "Organization not found.")
|
|
92
|
-
}
|
|
93
|
-
) });
|
|
94
|
-
}
|
|
95
|
-
if (success) {
|
|
96
|
-
return /* @__PURE__ */ jsxs("div", { className: "mx-auto w-full max-w-sm", children: [
|
|
97
|
-
/* @__PURE__ */ jsxs("div", { className: "mb-8 text-center", children: [
|
|
98
|
-
/* @__PURE__ */ jsx("h1", { className: "text-2xl font-bold tracking-tight", children: t("portal.resetPassword.success.title", "Password Reset Complete") }),
|
|
99
|
-
/* @__PURE__ */ jsx("p", { className: "mt-1.5 text-sm text-muted-foreground", children: t("portal.resetPassword.success.description", "Your password has been successfully reset.") })
|
|
100
|
-
] }),
|
|
101
|
-
/* @__PURE__ */ jsx(Alert, { children: /* @__PURE__ */ jsx(AlertDescription, { children: t("portal.resetPassword.success.message", "You can now sign in with your new password.") }) }),
|
|
102
|
-
/* @__PURE__ */ jsx("div", { className: "mt-6 text-center", children: /* @__PURE__ */ jsx(Link, { href: `/${orgSlug}/portal/login`, className: "font-medium text-foreground underline underline-offset-4 hover:opacity-80", children: t("portal.resetPassword.success.loginLink", "Go to Sign In") }) })
|
|
103
|
-
] });
|
|
104
|
-
}
|
|
105
|
-
return /* @__PURE__ */ jsxs("div", { className: "mx-auto w-full max-w-sm", children: [
|
|
106
|
-
/* @__PURE__ */ jsxs("div", { className: "mb-8 text-center", children: [
|
|
107
|
-
/* @__PURE__ */ jsx("h1", { className: "text-2xl font-bold tracking-tight", children: t("portal.resetPassword.title", "Reset Password") }),
|
|
108
|
-
/* @__PURE__ */ jsx("p", { className: "mt-1.5 text-sm text-muted-foreground", children: t("portal.resetPassword.description", "Enter your new password below.") })
|
|
109
|
-
] }),
|
|
110
|
-
/* @__PURE__ */ jsx(InjectionSpot, { spotId: extensionPoints.hosts.resetPasswordBefore.spotId, context: injectionContext }),
|
|
111
|
-
/* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "flex flex-col gap-4", children: [
|
|
112
|
-
error ? /* @__PURE__ */ jsx(Alert, { status: "error", children: /* @__PURE__ */ jsx(AlertDescription, { children: error }) }) : null,
|
|
113
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
|
|
114
|
-
/* @__PURE__ */ jsx(Label, { htmlFor: "reset-password", className: "text-overline font-semibold uppercase tracking-wider text-muted-foreground/70", children: t("portal.resetPassword.password", "New Password") }),
|
|
115
|
-
/* @__PURE__ */ jsx(PasswordInput, { id: "reset-password", autoComplete: "new-password", required: true, placeholder: t("portal.resetPassword.password.placeholder", "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"), value: password, onChange: (e) => setPassword(e.target.value), disabled: submitting || !token, className: "rounded-lg" })
|
|
116
|
-
] }),
|
|
117
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
|
|
118
|
-
/* @__PURE__ */ jsx(Label, { htmlFor: "confirm-password", className: "text-overline font-semibold uppercase tracking-wider text-muted-foreground/70", children: t("portal.resetPassword.confirmPassword", "Confirm New Password") }),
|
|
119
|
-
/* @__PURE__ */ jsx(PasswordInput, { id: "confirm-password", autoComplete: "new-password", required: true, placeholder: t("portal.resetPassword.confirmPassword.placeholder", "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"), value: confirmPassword, onChange: (e) => setConfirmPassword(e.target.value), disabled: submitting || !token, className: "rounded-lg" })
|
|
120
|
-
] }),
|
|
121
|
-
/* @__PURE__ */ jsx(Button, { type: "submit", disabled: submitting || !token, className: "mt-1 w-full rounded-lg", children: submitting ? t("portal.resetPassword.submitting", "Resetting password...") : t("portal.resetPassword.submit", "Reset Password") }),
|
|
122
|
-
/* @__PURE__ */ jsxs("p", { className: "text-center text-sm text-muted-foreground", children: [
|
|
123
|
-
t("portal.resetPassword.backToLogin", "Remember your password?"),
|
|
124
|
-
" ",
|
|
125
|
-
/* @__PURE__ */ jsx(Link, { href: `/${orgSlug}/portal/login`, className: "font-medium text-foreground underline underline-offset-4 hover:opacity-80", children: t("portal.resetPassword.loginLink", "Sign in") })
|
|
126
|
-
] })
|
|
127
|
-
] }),
|
|
128
|
-
/* @__PURE__ */ jsx(InjectionSpot, { spotId: extensionPoints.hosts.resetPasswordAfter.spotId, context: injectionContext })
|
|
129
|
-
] });
|
|
130
18
|
}
|
|
131
19
|
export {
|
|
132
20
|
PortalResetPasswordPage as default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/modules/portal/frontend/%5BorgSlug%5D/portal/reset-password/page.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\nimport {
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport { useMemo } from 'react'\nimport { extensionPoints } from '@open-mercato/core/modules/portal/extension-points'\nimport { InjectionSpot } from '@open-mercato/ui/backend/injection/InjectionSpot'\nimport { PortalPasswordForm } from '../PasswordForm'\n\nexport default function PortalResetPasswordPage({ params }: { params: { orgSlug: string } }) {\n const orgSlug = params.orgSlug\n const injectionContext = useMemo(() => ({ orgSlug }), [orgSlug])\n return (\n <PortalPasswordForm\n params={params}\n beforeForm={<InjectionSpot spotId={extensionPoints.hosts.resetPasswordBefore.spotId} context={injectionContext} />}\n afterForm={<InjectionSpot spotId={extensionPoints.hosts.resetPasswordAfter.spotId} context={injectionContext} />}\n />\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAYkB;AAXlB,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AAEpB,SAAR,wBAAyC,EAAE,OAAO,GAAoC;AAC3F,QAAM,UAAU,OAAO;AACvB,QAAM,mBAAmB,QAAQ,OAAO,EAAE,QAAQ,IAAI,CAAC,OAAO,CAAC;AAC/D,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,YAAY,oBAAC,iBAAc,QAAQ,gBAAgB,MAAM,oBAAoB,QAAQ,SAAS,kBAAkB;AAAA,MAChH,WAAW,oBAAC,iBAAc,QAAQ,gBAAgB,MAAM,mBAAmB,QAAQ,SAAS,kBAAkB;AAAA;AAAA,EAChH;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,7 +6,6 @@ import Link from "next/link";
|
|
|
6
6
|
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
7
7
|
import { Input } from "@open-mercato/ui/primitives/input";
|
|
8
8
|
import { EmailInput } from "@open-mercato/ui/primitives/email-input";
|
|
9
|
-
import { PasswordInput } from "@open-mercato/ui/primitives/password-input";
|
|
10
9
|
import { Label } from "@open-mercato/ui/primitives/label";
|
|
11
10
|
import { Button } from "@open-mercato/ui/primitives/button";
|
|
12
11
|
import { Alert, AlertDescription } from "@open-mercato/ui/primitives/alert";
|
|
@@ -22,7 +21,6 @@ function PortalSignupPage({ params }) {
|
|
|
22
21
|
const { tenant } = usePortalContext();
|
|
23
22
|
const [displayName, setDisplayName] = useState("");
|
|
24
23
|
const [email, setEmail] = useState("");
|
|
25
|
-
const [password, setPassword] = useState("");
|
|
26
24
|
const [error, setError] = useState(null);
|
|
27
25
|
const [fieldErrors, setFieldErrors] = useState({});
|
|
28
26
|
const [success, setSuccess] = useState(false);
|
|
@@ -41,7 +39,7 @@ function PortalSignupPage({ params }) {
|
|
|
41
39
|
const result = await apiCall("/api/customer_accounts/signup", {
|
|
42
40
|
method: "POST",
|
|
43
41
|
headers: { "Content-Type": "application/json" },
|
|
44
|
-
body: JSON.stringify({ email,
|
|
42
|
+
body: JSON.stringify({ email, displayName, organizationId: tenant.organizationId })
|
|
45
43
|
});
|
|
46
44
|
if (result.status === 202 && result.result?.ok) {
|
|
47
45
|
setSuccess(true);
|
|
@@ -56,8 +54,6 @@ function PortalSignupPage({ params }) {
|
|
|
56
54
|
mapped.displayName = t("portal.signup.error.displayName.required", "Full name is required.");
|
|
57
55
|
} else if (fieldKey === "email") {
|
|
58
56
|
mapped.email = t("portal.signup.error.email.invalid", "Please enter a valid email address.");
|
|
59
|
-
} else if (fieldKey === "password") {
|
|
60
|
-
mapped.password = t("portal.signup.error.password.minLength", "Password must be at least 8 characters.");
|
|
61
57
|
}
|
|
62
58
|
}
|
|
63
59
|
const hasUnmappedField = detailEntries.some(([fieldKey]) => !(fieldKey in mapped));
|
|
@@ -74,7 +70,7 @@ function PortalSignupPage({ params }) {
|
|
|
74
70
|
setSubmitting(false);
|
|
75
71
|
}
|
|
76
72
|
},
|
|
77
|
-
[displayName, email,
|
|
73
|
+
[displayName, email, tenant.organizationId, t]
|
|
78
74
|
);
|
|
79
75
|
const injectionContext = useMemo(
|
|
80
76
|
() => ({ orgSlug }),
|
|
@@ -123,11 +119,6 @@ function PortalSignupPage({ params }) {
|
|
|
123
119
|
/* @__PURE__ */ jsx(EmailInput, { id: "signup-email", required: true, placeholder: t("portal.signup.email.placeholder", "you@example.com"), value: email, onChange: (e) => setEmail(e.target.value), disabled: submitting, "aria-invalid": fieldErrors.email ? true : void 0, "aria-describedby": fieldErrors.email ? "signup-email-error" : void 0, className: "rounded-lg" }),
|
|
124
120
|
fieldErrors.email && /* @__PURE__ */ jsx("p", { id: "signup-email-error", role: "alert", className: "text-sm text-destructive", children: fieldErrors.email })
|
|
125
121
|
] }),
|
|
126
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
|
|
127
|
-
/* @__PURE__ */ jsx(Label, { htmlFor: "signup-password", className: "text-overline font-semibold uppercase tracking-wider text-muted-foreground/70", children: t("portal.signup.password", "Password") }),
|
|
128
|
-
/* @__PURE__ */ jsx(PasswordInput, { id: "signup-password", autoComplete: "new-password", required: true, placeholder: t("portal.signup.password.placeholder", "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"), value: password, onChange: (e) => setPassword(e.target.value), disabled: submitting, "aria-invalid": fieldErrors.password ? true : void 0, "aria-describedby": fieldErrors.password ? "signup-password-error" : void 0, className: "rounded-lg" }),
|
|
129
|
-
fieldErrors.password && /* @__PURE__ */ jsx("p", { id: "signup-password-error", role: "alert", className: "text-sm text-destructive", children: fieldErrors.password })
|
|
130
|
-
] }),
|
|
131
122
|
/* @__PURE__ */ jsx(Button, { type: "submit", disabled: submitting, className: "mt-1 w-full rounded-lg", children: submitting ? t("portal.signup.submitting", "Creating account...") : t("portal.signup.submit", "Create Account") }),
|
|
132
123
|
/* @__PURE__ */ jsxs("p", { className: "text-center text-sm text-muted-foreground", children: [
|
|
133
124
|
t("portal.signup.hasAccount", "Already have an account?"),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/modules/portal/frontend/%5BorgSlug%5D/portal/signup/page.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\nimport { useCallback, useMemo, useState } from 'react'\nimport { extensionPoints } from '@open-mercato/core/modules/portal/extension-points'\nimport Link from 'next/link'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Input } from '@open-mercato/ui/primitives/input'\nimport { EmailInput } from '@open-mercato/ui/primitives/email-input'\nimport {
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport { useCallback, useMemo, useState } from 'react'\nimport { extensionPoints } from '@open-mercato/core/modules/portal/extension-points'\nimport Link from 'next/link'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Input } from '@open-mercato/ui/primitives/input'\nimport { EmailInput } from '@open-mercato/ui/primitives/email-input'\nimport { Label } from '@open-mercato/ui/primitives/label'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { Alert, AlertDescription } from '@open-mercato/ui/primitives/alert'\nimport { EmptyState } from '@open-mercato/ui/primitives/empty-state'\nimport { SearchX, Check } from 'lucide-react'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\nimport { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport { usePortalContext } from '@open-mercato/ui/portal/PortalContext'\nimport { InjectionSpot } from '@open-mercato/ui/backend/injection/InjectionSpot'\n\ntype Props = { params: { orgSlug: string } }\ntype SignupResponse = { ok: boolean; error?: string; details?: Record<string, string[]> }\n\nexport default function PortalSignupPage({ params }: Props) {\n const t = useT()\n const orgSlug = params.orgSlug\n const { tenant } = usePortalContext()\n\n const [displayName, setDisplayName] = useState('')\n const [email, setEmail] = useState('')\n const [error, setError] = useState<string | null>(null)\n const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({})\n const [success, setSuccess] = useState(false)\n const [submitting, setSubmitting] = useState(false)\n\n const handleSubmit = useCallback(\n async (event: React.FormEvent) => {\n event.preventDefault()\n setError(null)\n setFieldErrors({})\n\n if (!tenant.organizationId) {\n setError(t('portal.org.invalid', 'Organization not found.'))\n return\n }\n\n setSubmitting(true)\n try {\n const result = await apiCall<SignupResponse>('/api/customer_accounts/signup', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ email, displayName, organizationId: tenant.organizationId }),\n })\n\n if (result.status === 202 && result.result?.ok) {\n setSuccess(true)\n return\n }\n\n const details = result.result?.details\n const detailEntries = details ? Object.entries(details).filter(([, messages]) => (messages?.length ?? 0) > 0) : []\n if (detailEntries.length > 0) {\n // API detail values are raw untranslated validator strings; each known field maps to one translated message instead.\n const mapped: Record<string, string> = {}\n for (const [fieldKey] of detailEntries) {\n if (fieldKey === 'displayName') {\n mapped.displayName = t('portal.signup.error.displayName.required', 'Full name is required.')\n } else if (fieldKey === 'email') {\n mapped.email = t('portal.signup.error.email.invalid', 'Please enter a valid email address.')\n }\n }\n const hasUnmappedField = detailEntries.some(([fieldKey]) => !(fieldKey in mapped))\n setFieldErrors(mapped)\n if (hasUnmappedField || Object.keys(mapped).length === 0) {\n setError(result.result?.error || t('portal.signup.error.generic', 'Signup failed. Please try again.'))\n }\n } else {\n setError(result.result?.error || t('portal.signup.error.generic', 'Signup failed. Please try again.'))\n }\n } catch {\n setError(t('portal.signup.error.generic', 'Signup failed. Please try again.'))\n } finally {\n setSubmitting(false)\n }\n },\n [displayName, email, tenant.organizationId, t],\n )\n\n const injectionContext = useMemo(\n () => ({ orgSlug }),\n [orgSlug],\n )\n\n if (tenant.loading) {\n return <div className=\"flex items-center justify-center py-20\"><Spinner /></div>\n }\n\n if (tenant.error) {\n return (\n <div className=\"mx-auto w-full max-w-md py-12\">\n <EmptyState\n variant=\"subtle\"\n size=\"lg\"\n icon={<SearchX className=\"h-6 w-6\" aria-hidden />}\n title={t('portal.org.invalid', 'Organization not found.')}\n />\n </div>\n )\n }\n\n if (success) {\n return (\n <div className=\"mx-auto w-full max-w-sm text-center\">\n <div className=\"mx-auto mb-4 flex size-12 items-center justify-center rounded-full bg-foreground text-background\">\n <Check className=\"size-6\" />\n </div>\n <h1 className=\"text-2xl font-bold tracking-tight\">{t('portal.signup.success.title', 'Check your email')}</h1>\n <p className=\"mt-1.5 text-sm text-muted-foreground\">{t(\n 'portal.signup.success.description',\n 'If your registration was accepted, check your email for next steps before signing in. Some organizations require an administrator to activate new accounts.',\n )}</p>\n <Button asChild className=\"mt-6 w-full rounded-lg\">\n <Link href={`/${orgSlug}/portal/login`}>{t('portal.signup.success.loginLink', 'Sign In')}</Link>\n </Button>\n </div>\n )\n }\n\n return (\n <div className=\"mx-auto w-full max-w-sm\">\n <div className=\"mb-8 text-center\">\n <h1 className=\"text-2xl font-bold tracking-tight\">{t('portal.signup.title', 'Create Account')}</h1>\n <p className=\"mt-1.5 text-sm text-muted-foreground\">{t('portal.signup.description', 'Sign up for a portal account.')}</p>\n </div>\n\n <InjectionSpot spotId={extensionPoints.hosts.signupBefore.spotId} context={injectionContext} />\n\n <form onSubmit={handleSubmit} className=\"flex flex-col gap-4\">\n {error ? (\n <Alert status=\"error\">\n <AlertDescription>{error}</AlertDescription>\n </Alert>\n ) : null}\n\n <div className=\"flex flex-col gap-1.5\">\n <Label htmlFor=\"signup-name\" className=\"text-overline font-semibold uppercase tracking-wider text-muted-foreground/70\">{t('portal.signup.displayName', 'Full Name')}</Label>\n <Input id=\"signup-name\" type=\"text\" autoComplete=\"name\" required placeholder={t('portal.signup.displayName.placeholder', 'Jane Smith')} value={displayName} onChange={(e) => setDisplayName(e.target.value)} disabled={submitting} aria-invalid={fieldErrors.displayName ? true : undefined} aria-describedby={fieldErrors.displayName ? 'signup-name-error' : undefined} className=\"rounded-lg\" />\n {fieldErrors.displayName && <p id=\"signup-name-error\" role=\"alert\" className=\"text-sm text-destructive\">{fieldErrors.displayName}</p>}\n </div>\n\n <div className=\"flex flex-col gap-1.5\">\n <Label htmlFor=\"signup-email\" className=\"text-overline font-semibold uppercase tracking-wider text-muted-foreground/70\">{t('portal.signup.email', 'Email')}</Label>\n <EmailInput id=\"signup-email\" required placeholder={t('portal.signup.email.placeholder', 'you@example.com')} value={email} onChange={(e) => setEmail(e.target.value)} disabled={submitting} aria-invalid={fieldErrors.email ? true : undefined} aria-describedby={fieldErrors.email ? 'signup-email-error' : undefined} className=\"rounded-lg\" />\n {fieldErrors.email && <p id=\"signup-email-error\" role=\"alert\" className=\"text-sm text-destructive\">{fieldErrors.email}</p>}\n </div>\n\n <Button type=\"submit\" disabled={submitting} className=\"mt-1 w-full rounded-lg\">\n {submitting ? t('portal.signup.submitting', 'Creating account...') : t('portal.signup.submit', 'Create Account')}\n </Button>\n\n <p className=\"text-center text-sm text-muted-foreground\">\n {t('portal.signup.hasAccount', 'Already have an account?')}{' '}\n <Link href={`/${orgSlug}/portal/login`} className=\"font-medium text-foreground underline underline-offset-4 hover:opacity-80\">\n {t('portal.signup.loginLink', 'Sign in')}\n </Link>\n </p>\n </form>\n\n <InjectionSpot spotId={extensionPoints.hosts.signupAfter.spotId} context={injectionContext} />\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AA2FmE,cAkB7D,YAlB6D;AA1FnE,SAAS,aAAa,SAAS,gBAAgB;AAC/C,SAAS,uBAAuB;AAChC,OAAO,UAAU;AACjB,SAAS,YAAY;AACrB,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,cAAc;AACvB,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,sBAAY,aAAY;AAAA,SACnI;AAAA,MAEA,qBAAC,SAAI,WAAU,yBACb;AAAA,4BAAC,SAAM,SAAQ,gBAAe,WAAU,iFAAiF,YAAE,uBAAuB,OAAO,GAAE;AAAA,QAC3J,oBAAC,cAAW,IAAG,gBAAe,UAAQ,MAAC,aAAa,EAAE,mCAAmC,iBAAiB,GAAG,OAAO,OAAO,UAAU,CAAC,MAAM,SAAS,EAAE,OAAO,KAAK,GAAG,UAAU,YAAY,gBAAc,YAAY,QAAQ,OAAO,QAAW,oBAAkB,YAAY,QAAQ,uBAAuB,QAAW,WAAU,cAAa;AAAA,QAC9U,YAAY,SAAS,oBAAC,OAAE,IAAG,sBAAqB,MAAK,SAAQ,WAAU,4BAA4B,sBAAY,OAAM;AAAA,SACxH;AAAA,MAEA,oBAAC,UAAO,MAAK,UAAS,UAAU,YAAY,WAAU,0BACnD,uBAAa,EAAE,4BAA4B,qBAAqB,IAAI,EAAE,wBAAwB,gBAAgB,GACjH;AAAA,MAEA,qBAAC,OAAE,WAAU,6CACV;AAAA,UAAE,4BAA4B,0BAA0B;AAAA,QAAG;AAAA,QAC5D,oBAAC,QAAK,MAAM,IAAI,OAAO,iBAAiB,WAAU,6EAC/C,YAAE,2BAA2B,SAAS,GACzC;AAAA,SACF;AAAA,OACF;AAAA,IAEA,oBAAC,iBAAc,QAAQ,gBAAgB,MAAM,YAAY,QAAQ,SAAS,kBAAkB;AAAA,KAC9F;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,66 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx
|
|
3
|
-
import {
|
|
4
|
-
import Link from "next/link";
|
|
5
|
-
import { useSearchParams } from "next/navigation";
|
|
6
|
-
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
7
|
-
import { apiCall } from "@open-mercato/ui/backend/utils/apiCall";
|
|
8
|
-
import { Button } from "@open-mercato/ui/primitives/button";
|
|
9
|
-
import { Alert, AlertDescription } from "@open-mercato/ui/primitives/alert";
|
|
10
|
-
import { Spinner } from "@open-mercato/ui/primitives/spinner";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { PortalPasswordForm } from "../PasswordForm.js";
|
|
11
4
|
function PortalVerifyPage({ params }) {
|
|
12
|
-
|
|
13
|
-
const searchParams = useSearchParams();
|
|
14
|
-
const token = searchParams.get("token") ?? "";
|
|
15
|
-
const [state, setState] = useState(token ? "verifying" : "error");
|
|
16
|
-
const [error, setError] = useState(token ? null : t("portal.verify.error.invalidToken", "Verification token is missing."));
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
if (!token) return;
|
|
19
|
-
let active = true;
|
|
20
|
-
void apiCall("/api/customer_accounts/email/verify", {
|
|
21
|
-
method: "POST",
|
|
22
|
-
headers: { "Content-Type": "application/json" },
|
|
23
|
-
body: JSON.stringify({ token })
|
|
24
|
-
}).then((result) => {
|
|
25
|
-
if (!active) return;
|
|
26
|
-
if (result.ok && result.result?.ok) {
|
|
27
|
-
setState("success");
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
setState("error");
|
|
31
|
-
setError(result.result?.error || t("portal.verify.error.generic", "Email verification failed. Please try again."));
|
|
32
|
-
}).catch(() => {
|
|
33
|
-
if (!active) return;
|
|
34
|
-
setState("error");
|
|
35
|
-
setError(t("portal.verify.error.generic", "Email verification failed. Please try again."));
|
|
36
|
-
});
|
|
37
|
-
return () => {
|
|
38
|
-
active = false;
|
|
39
|
-
};
|
|
40
|
-
}, [token, t]);
|
|
41
|
-
if (state === "verifying") {
|
|
42
|
-
return /* @__PURE__ */ jsxs("div", { className: "mx-auto flex max-w-sm flex-col items-center gap-4 py-12 text-center", children: [
|
|
43
|
-
/* @__PURE__ */ jsx(Spinner, {}),
|
|
44
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
45
|
-
/* @__PURE__ */ jsx("h1", { className: "text-2xl font-bold tracking-tight", children: t("portal.verify.title", "Verifying email") }),
|
|
46
|
-
/* @__PURE__ */ jsx("p", { className: "mt-1.5 text-sm text-muted-foreground", children: t("portal.verify.description", "Please wait while we verify your email address.") })
|
|
47
|
-
] })
|
|
48
|
-
] });
|
|
49
|
-
}
|
|
50
|
-
if (state === "success") {
|
|
51
|
-
return /* @__PURE__ */ jsxs("div", { className: "mx-auto flex max-w-sm flex-col items-center gap-4 py-12 text-center", children: [
|
|
52
|
-
/* @__PURE__ */ jsx("div", { className: "mx-auto flex size-12 items-center justify-center rounded-full bg-foreground text-background", children: /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", className: "size-6", children: /* @__PURE__ */ jsx("polyline", { points: "20 6 9 17 4 12" }) }) }),
|
|
53
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
54
|
-
/* @__PURE__ */ jsx("h1", { className: "text-2xl font-bold tracking-tight", children: t("portal.verify.success.title", "Email verified") }),
|
|
55
|
-
/* @__PURE__ */ jsx("p", { className: "mt-1.5 text-sm text-muted-foreground", children: t("portal.verify.success.description", "Your email has been verified. You can now sign in to the portal.") })
|
|
56
|
-
] }),
|
|
57
|
-
/* @__PURE__ */ jsx(Button, { asChild: true, className: "w-full rounded-lg", children: /* @__PURE__ */ jsx(Link, { href: `/${params.orgSlug}/portal/login`, children: t("portal.verify.success.loginLink", "Sign In") }) })
|
|
58
|
-
] });
|
|
59
|
-
}
|
|
60
|
-
return /* @__PURE__ */ jsxs("div", { className: "mx-auto flex max-w-sm flex-col gap-4 py-12", children: [
|
|
61
|
-
/* @__PURE__ */ jsx(Alert, { status: "error", children: /* @__PURE__ */ jsx(AlertDescription, { children: error || t("portal.verify.error.generic", "Email verification failed. Please try again.") }) }),
|
|
62
|
-
/* @__PURE__ */ jsx(Button, { asChild: true, variant: "outline", className: "rounded-lg", children: /* @__PURE__ */ jsx(Link, { href: `/${params.orgSlug}/portal/login`, children: t("portal.verify.error.backToLogin", "Back to sign in") }) })
|
|
63
|
-
] });
|
|
5
|
+
return /* @__PURE__ */ jsx(PortalPasswordForm, { params, verify: true });
|
|
64
6
|
}
|
|
65
7
|
export {
|
|
66
8
|
PortalVerifyPage as default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/modules/portal/frontend/%5BorgSlug%5D/portal/verify/page.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\nimport {
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport { PortalPasswordForm } from '../PasswordForm'\n\nexport default function PortalVerifyPage({ params }: { params: { orgSlug: string } }) {\n return <PortalPasswordForm params={params} verify />\n}\n"],
|
|
5
|
+
"mappings": ";AAIS;AAHT,SAAS,0BAA0B;AAEpB,SAAR,iBAAkC,EAAE,OAAO,GAAoC;AACpF,SAAO,oBAAC,sBAAmB,QAAgB,QAAM,MAAC;AACpD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/core",
|
|
3
|
-
"version": "0.11.1-develop.
|
|
3
|
+
"version": "0.11.1-develop.8549.1.bd34c91190",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -268,16 +268,16 @@
|
|
|
268
268
|
"zod": "^4.6.6"
|
|
269
269
|
},
|
|
270
270
|
"peerDependencies": {
|
|
271
|
-
"@open-mercato/ai-assistant": "0.11.1-develop.
|
|
272
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
273
|
-
"@open-mercato/ui": "0.11.1-develop.
|
|
271
|
+
"@open-mercato/ai-assistant": "0.11.1-develop.8549.1.bd34c91190",
|
|
272
|
+
"@open-mercato/shared": "0.11.1-develop.8549.1.bd34c91190",
|
|
273
|
+
"@open-mercato/ui": "0.11.1-develop.8549.1.bd34c91190",
|
|
274
274
|
"react": "^19.0.0",
|
|
275
275
|
"react-dom": "^19.0.0"
|
|
276
276
|
},
|
|
277
277
|
"devDependencies": {
|
|
278
|
-
"@open-mercato/ai-assistant": "0.11.1-develop.
|
|
279
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
280
|
-
"@open-mercato/ui": "0.11.1-develop.
|
|
278
|
+
"@open-mercato/ai-assistant": "0.11.1-develop.8549.1.bd34c91190",
|
|
279
|
+
"@open-mercato/shared": "0.11.1-develop.8549.1.bd34c91190",
|
|
280
|
+
"@open-mercato/ui": "0.11.1-develop.8549.1.bd34c91190",
|
|
281
281
|
"@testing-library/dom": "^10.4.1",
|
|
282
282
|
"@testing-library/jest-dom": "^7.0.1",
|
|
283
283
|
"@testing-library/react": "^16.3.3",
|
|
@@ -4,9 +4,8 @@ import type { OpenApiRouteDoc, OpenApiMethodDoc } from '@open-mercato/shared/lib
|
|
|
4
4
|
import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
|
|
5
5
|
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
6
6
|
import { RbacService } from '@open-mercato/core/modules/auth/services/rbacService'
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
7
|
+
import type { CustomerSessionService } from '../../../../services/customerSessionService'
|
|
8
|
+
import { emitCustomerEmailVerified, verifyCustomerEmail } from '../../../../lib/verifyCustomerEmail'
|
|
10
9
|
|
|
11
10
|
export const metadata = {}
|
|
12
11
|
|
|
@@ -25,40 +24,19 @@ export async function POST(req: Request, { params }: { params: { id: string } })
|
|
|
25
24
|
|
|
26
25
|
const em = container.resolve('em') as import('@mikro-orm/postgresql').EntityManager
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
em,
|
|
30
|
-
CustomerUser,
|
|
31
|
-
{
|
|
32
|
-
id: params.id,
|
|
33
|
-
tenantId: auth.tenantId,
|
|
34
|
-
organizationId: auth.orgId,
|
|
35
|
-
deletedAt: null,
|
|
36
|
-
} as any,
|
|
37
|
-
undefined,
|
|
38
|
-
{ tenantId: auth.tenantId, organizationId: auth.orgId },
|
|
39
|
-
)
|
|
40
|
-
if (!user) {
|
|
27
|
+
if (!auth.tenantId || !auth.orgId) {
|
|
41
28
|
return NextResponse.json({ ok: false, error: 'User not found' }, { status: 404 })
|
|
42
29
|
}
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
const scope = { userId: params.id, tenantId: auth.tenantId, organizationId: auth.orgId }
|
|
31
|
+
const sessions = container.resolve<CustomerSessionService>('customerSessionService')
|
|
32
|
+
const result = await em.transactional((tx) => verifyCustomerEmail(tx, scope, sessions))
|
|
33
|
+
if (!result) {
|
|
34
|
+
return NextResponse.json({ ok: false, error: 'User not found' }, { status: 404 })
|
|
35
|
+
}
|
|
36
|
+
if (!result.newlyVerified) {
|
|
45
37
|
return NextResponse.json({ ok: true, alreadyVerified: true })
|
|
46
38
|
}
|
|
47
|
-
|
|
48
|
-
await em.nativeUpdate(CustomerUser, {
|
|
49
|
-
id: user.id,
|
|
50
|
-
tenantId: user.tenantId,
|
|
51
|
-
organizationId: user.organizationId,
|
|
52
|
-
}, { emailVerifiedAt: new Date() })
|
|
53
|
-
|
|
54
|
-
void emitCustomerAccountsEvent('customer_accounts.email.verified', {
|
|
55
|
-
id: user.id,
|
|
56
|
-
recipientUserId: user.id,
|
|
57
|
-
email: user.email,
|
|
58
|
-
tenantId: user.tenantId,
|
|
59
|
-
organizationId: user.organizationId,
|
|
60
|
-
verifiedBy: auth.sub,
|
|
61
|
-
}).catch(() => undefined)
|
|
39
|
+
emitCustomerEmailVerified(result.user, auth.sub)
|
|
62
40
|
|
|
63
41
|
return NextResponse.json({ ok: true })
|
|
64
42
|
}
|
|
@@ -4,8 +4,9 @@ import type { OpenApiRouteDoc, OpenApiMethodDoc } from '@open-mercato/shared/lib
|
|
|
4
4
|
import { emailVerifySchema } from '@open-mercato/core/modules/customer_accounts/data/validators'
|
|
5
5
|
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
6
6
|
import { CustomerTokenService } from '@open-mercato/core/modules/customer_accounts/services/customerTokenService'
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import type { CustomerSessionService } from '../../services/customerSessionService'
|
|
8
|
+
import type { CustomerUserService } from '../../services/customerUserService'
|
|
9
|
+
import { emitCustomerEmailVerified, verifyCustomerEmail } from '../../lib/verifyCustomerEmail'
|
|
9
10
|
|
|
10
11
|
export const metadata: { path?: string; requireAuth?: boolean } = { requireAuth: false }
|
|
11
12
|
|
|
@@ -26,18 +27,21 @@ export async function POST(req: Request) {
|
|
|
26
27
|
const customerTokenService = container.resolve('customerTokenService') as CustomerTokenService
|
|
27
28
|
const em = container.resolve('em') as import('@mikro-orm/postgresql').EntityManager
|
|
28
29
|
|
|
29
|
-
const
|
|
30
|
+
const sessions = container.resolve<CustomerSessionService>('customerSessionService')
|
|
31
|
+
const { token, password } = parsed.data
|
|
32
|
+
const result = await em.transactional(async (tx) => {
|
|
33
|
+
const identity = await customerTokenService.verifyEmailToken(token, 'email_verification', undefined, tx)
|
|
34
|
+
if (!identity) return null
|
|
35
|
+
const credentials = password === undefined
|
|
36
|
+
? undefined
|
|
37
|
+
: { password, users: container.resolve<CustomerUserService>('customerUserService') }
|
|
38
|
+
return verifyCustomerEmail(tx, identity, sessions, credentials)
|
|
39
|
+
})
|
|
30
40
|
if (!result) {
|
|
31
41
|
return NextResponse.json({ ok: false, error: 'Invalid or expired token' }, { status: 400 })
|
|
32
42
|
}
|
|
33
43
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
void emitCustomerAccountsEvent('customer_accounts.email.verified', {
|
|
37
|
-
userId: result.userId,
|
|
38
|
-
recipientUserId: result.userId,
|
|
39
|
-
tenantId: result.tenantId,
|
|
40
|
-
}).catch(() => undefined)
|
|
44
|
+
if (result.newlyVerified) emitCustomerEmailVerified(result.user)
|
|
41
45
|
|
|
42
46
|
return NextResponse.json({ ok: true })
|
|
43
47
|
}
|
|
@@ -47,7 +51,7 @@ const errorSchema = z.object({ ok: z.literal(false), error: z.string() })
|
|
|
47
51
|
|
|
48
52
|
const methodDoc: OpenApiMethodDoc = {
|
|
49
53
|
summary: 'Verify customer email address',
|
|
50
|
-
description: '
|
|
54
|
+
description: 'Verifies the email and optionally sets a password chosen by the email recipient.',
|
|
51
55
|
tags: ['Customer Authentication'],
|
|
52
56
|
requestBody: {
|
|
53
57
|
schema: emailVerifySchema,
|
|
@@ -7,8 +7,8 @@ import { CustomerTokenService } from '@open-mercato/core/modules/customer_accoun
|
|
|
7
7
|
import { CustomerUserService } from '@open-mercato/core/modules/customer_accounts/services/customerUserService'
|
|
8
8
|
import { CustomerSessionService } from '@open-mercato/core/modules/customer_accounts/services/customerSessionService'
|
|
9
9
|
import { CustomerRbacService } from '@open-mercato/core/modules/customer_accounts/services/customerRbacService'
|
|
10
|
-
import { CustomerUser } from '@open-mercato/core/modules/customer_accounts/data/entities'
|
|
11
10
|
import { emitCustomerAccountsEvent } from '@open-mercato/core/modules/customer_accounts/events'
|
|
11
|
+
import { emitCustomerEmailVerified, verifyCustomerEmail } from '../../lib/verifyCustomerEmail'
|
|
12
12
|
import { getClientIp } from '@open-mercato/shared/lib/ratelimit/helpers'
|
|
13
13
|
import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
14
14
|
import { isCrossSiteBrowserRequest } from '@open-mercato/shared/lib/url'
|
|
@@ -39,21 +39,21 @@ export async function POST(req: Request) {
|
|
|
39
39
|
const customerRbacService = container.resolve('customerRbacService') as CustomerRbacService
|
|
40
40
|
const em = container.resolve('em') as import('@mikro-orm/postgresql').EntityManager
|
|
41
41
|
|
|
42
|
-
const result = await
|
|
42
|
+
const result = await em.transactional(async (tx) => {
|
|
43
|
+
const identity = await customerTokenService.verifyEmailToken(parsed.data.token, 'magic_link', undefined, tx)
|
|
44
|
+
if (!identity) return null
|
|
45
|
+
return { account: await verifyCustomerEmail(tx, identity, customerSessionService) }
|
|
46
|
+
})
|
|
43
47
|
if (!result) {
|
|
44
48
|
return NextResponse.json({ ok: false, error: 'Invalid or expired token' }, { status: 400 })
|
|
45
49
|
}
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
if (!user || !user.isActive) {
|
|
51
|
+
if (!result.account) {
|
|
49
52
|
return NextResponse.json({ ok: false, error: 'Account not found or deactivated' }, { status: 401 })
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
await em.nativeUpdate(CustomerUser, { id: user.id }, { emailVerifiedAt: new Date() })
|
|
55
|
-
user.emailVerifiedAt = new Date()
|
|
56
|
-
}
|
|
55
|
+
const { user, newlyVerified } = result.account
|
|
56
|
+
if (newlyVerified) emitCustomerEmailVerified(user)
|
|
57
57
|
|
|
58
58
|
await customerUserService.resetFailedAttempts(user)
|
|
59
59
|
await customerUserService.updateLastLoginAt(user)
|