hazo_auth 10.8.2 → 10.11.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.
Files changed (77) hide show
  1. package/README.md +40 -0
  2. package/SETUP_CHECKLIST.md +49 -0
  3. package/cli-src/cli/generate.ts +1 -0
  4. package/cli-src/lib/auth/with_auth.server.ts +65 -23
  5. package/cli-src/lib/cookies_config.server.ts +50 -0
  6. package/cli-src/lib/my_settings_config.server.ts +5 -1
  7. package/cli-src/lib/services/account_deletion_service.ts +67 -0
  8. package/cli-src/lib/services/index.ts +1 -0
  9. package/config/hazo_auth_config.example.ini +25 -19
  10. package/dist/admin-issues/install_permission_ux.server.d.ts +26 -0
  11. package/dist/admin-issues/install_permission_ux.server.d.ts.map +1 -0
  12. package/dist/admin-issues/install_permission_ux.server.js +27 -0
  13. package/dist/admin-issues/permission_denied_provider.client.d.ts +19 -0
  14. package/dist/admin-issues/permission_denied_provider.client.d.ts.map +1 -1
  15. package/dist/admin-issues/permission_denied_provider.client.js +46 -2
  16. package/dist/cli/generate.d.ts.map +1 -1
  17. package/dist/cli/generate.js +1 -0
  18. package/dist/client.d.ts +2 -2
  19. package/dist/client.d.ts.map +1 -1
  20. package/dist/client.js +1 -1
  21. package/dist/components/layouts/my_settings/components/danger_zone_section.d.ts +34 -0
  22. package/dist/components/layouts/my_settings/components/danger_zone_section.d.ts.map +1 -0
  23. package/dist/components/layouts/my_settings/components/danger_zone_section.js +93 -0
  24. package/dist/components/layouts/my_settings/index.d.ts +6 -1
  25. package/dist/components/layouts/my_settings/index.d.ts.map +1 -1
  26. package/dist/components/layouts/my_settings/index.js +3 -2
  27. package/dist/components/permission_denied_dialog.client.js +1 -1
  28. package/dist/components/ui/button.d.ts +1 -1
  29. package/dist/hooks.d.ts +5 -0
  30. package/dist/hooks.d.ts.map +1 -0
  31. package/dist/hooks.js +29 -0
  32. package/dist/lib/auth/with_auth.server.d.ts.map +1 -1
  33. package/dist/lib/auth/with_auth.server.js +51 -15
  34. package/dist/lib/cookies_config.server.d.ts +20 -0
  35. package/dist/lib/cookies_config.server.d.ts.map +1 -1
  36. package/dist/lib/cookies_config.server.js +43 -0
  37. package/dist/lib/my_settings_config.server.d.ts +2 -0
  38. package/dist/lib/my_settings_config.server.d.ts.map +1 -1
  39. package/dist/lib/my_settings_config.server.js +3 -1
  40. package/dist/lib/services/account_deletion_service.d.ts +22 -0
  41. package/dist/lib/services/account_deletion_service.d.ts.map +1 -0
  42. package/dist/lib/services/account_deletion_service.js +55 -0
  43. package/dist/lib/services/index.d.ts +1 -0
  44. package/dist/lib/services/index.d.ts.map +1 -1
  45. package/dist/lib/services/index.js +1 -0
  46. package/dist/page_components/my_settings.d.ts +6 -1
  47. package/dist/page_components/my_settings.d.ts.map +1 -1
  48. package/dist/page_components/my_settings.js +2 -2
  49. package/dist/server/routes/delete_account.d.ts +17 -0
  50. package/dist/server/routes/delete_account.d.ts.map +1 -0
  51. package/dist/server/routes/delete_account.js +107 -0
  52. package/dist/server/routes/index.d.ts +1 -0
  53. package/dist/server/routes/index.d.ts.map +1 -1
  54. package/dist/server/routes/index.js +1 -0
  55. package/dist/server/routes/logout.d.ts.map +1 -1
  56. package/dist/server/routes/logout.js +4 -40
  57. package/dist/server-lib.d.ts +2 -0
  58. package/dist/server-lib.d.ts.map +1 -1
  59. package/dist/server-lib.js +1 -0
  60. package/dist/server_pages/my_settings.d.ts.map +1 -1
  61. package/dist/server_pages/my_settings.js +1 -1
  62. package/package.json +15 -11
  63. package/dist/page_components/forgot_password.d.ts +0 -19
  64. package/dist/page_components/forgot_password.d.ts.map +0 -1
  65. package/dist/page_components/forgot_password.js +0 -50
  66. package/dist/page_components/login.d.ts +0 -30
  67. package/dist/page_components/login.d.ts.map +0 -1
  68. package/dist/page_components/login.js +0 -50
  69. package/dist/page_components/register.d.ts +0 -25
  70. package/dist/page_components/register.d.ts.map +0 -1
  71. package/dist/page_components/register.js +0 -57
  72. package/dist/page_components/reset_password.d.ts +0 -25
  73. package/dist/page_components/reset_password.d.ts.map +0 -1
  74. package/dist/page_components/reset_password.js +0 -57
  75. package/dist/page_components/verify_email.d.ts +0 -21
  76. package/dist/page_components/verify_email.d.ts.map +0 -1
  77. package/dist/page_components/verify_email.js +0 -50
@@ -16,6 +16,7 @@ const ROUTES = [
16
16
  { name: "change_password", path: "api/hazo_auth/change_password", method: "POST", export_name: "changePasswordPOST" },
17
17
  { name: "upload_profile_picture", path: "api/hazo_auth/upload_profile_picture", method: "POST", export_name: "uploadProfilePicturePOST" },
18
18
  { name: "remove_profile_picture", path: "api/hazo_auth/remove_profile_picture", method: "DELETE", export_name: "removeProfilePictureDELETE" },
19
+ { name: "delete_account", path: "api/hazo_auth/delete_account", method: "DELETE", export_name: "deleteAccountDELETE" },
19
20
  { name: "library_photos", path: "api/hazo_auth/library_photos", method: "GET", export_name: "libraryPhotosGET" },
20
21
  { name: "library_photo", path: "api/hazo_auth/library_photo/[category]/[filename]", method: "GET", export_name: "libraryPhotoGET" },
21
22
  { name: "get_auth", path: "api/hazo_auth/get_auth", method: "POST", export_name: "getAuthPOST" },
package/dist/client.d.ts CHANGED
@@ -15,6 +15,6 @@ export type { PermissionDeniedDialogProps, PermissionDeniedDetails } from "./com
15
15
  export { UserPickerSelect, UserAvatar, userDisplayName } from "./components/user_picker_select.js";
16
16
  export type { UserPickerSelectProps, UserAvatarProps, PickableUser, } from "./components/user_picker_select";
17
17
  export { AuthIssueCard, registerAuthIssueCardRenderer } from './admin-issues/plugin.client.js';
18
- export { PermissionDeniedProvider, showPermissionDeniedDialog, handlePermissionDenied, fetchWithPermissionCapture, } from './admin-issues/permission_denied_provider.client.js';
19
- export type { PermissionDeniedProviderProps } from './admin-issues/permission_denied_provider.client';
18
+ export { PermissionDeniedProvider, PermissionFailureProvider, showPermissionDeniedDialog, registerPermissionFailureSurface, handlePermissionDenied, fetchWithPermissionCapture, } from './admin-issues/permission_denied_provider.client.js';
19
+ export type { PermissionDeniedProviderProps, PermissionFailureProviderProps, PermissionFailureSurface, } from './admin-issues/permission_denied_provider.client';
20
20
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAYA,cAAc,oBAAoB,CAAC;AAInC,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAInI,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIpD,cAAc,uBAAuB,CAAC;AAItC,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAC;AACjH,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AAC3G,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AAC7G,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,qDAAqD,CAAC;AACnH,YAAY,EAAE,YAAY,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,qDAAqD,CAAC;AAGvI,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAIxG,cAAc,8CAA8C,CAAC;AAG7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAGvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAC;AACtF,YAAY,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAC;AAKzH,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAChG,YAAY,EACV,qBAAqB,EACrB,eAAe,EACf,YAAY,GACb,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAG5F,OAAO,EACL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AA6B,EAAE,MAAM,8BAA8B,CAAC;AAG5F,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,gCAAgC,EAChC,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,kDAAkD,CAAC;AAC1D,YAAY,EACV,6BAA6B,EAC7B,8BAA8B,EAC9B,wBAAwB,GACzB,MAAM,kDAAkD,CAAC"}
package/dist/client.js CHANGED
@@ -40,4 +40,4 @@ export { UserPickerSelect, UserAvatar, userDisplayName } from "./components/user
40
40
  // admin-issues plugin (client card renderer)
41
41
  export { AuthIssueCard, registerAuthIssueCardRenderer } from './admin-issues/plugin.client.js';
42
42
  // permission-denied provider + fetch helper
43
- export { PermissionDeniedProvider, showPermissionDeniedDialog, handlePermissionDenied, fetchWithPermissionCapture, } from './admin-issues/permission_denied_provider.client.js';
43
+ export { PermissionDeniedProvider, PermissionFailureProvider, showPermissionDeniedDialog, registerPermissionFailureSurface, handlePermissionDenied, fetchWithPermissionCapture, } from './admin-issues/permission_denied_provider.client.js';
@@ -0,0 +1,34 @@
1
+ export type DangerZoneSectionProps = {
2
+ /** Current user's email address — must be re-typed (case-insensitively) to confirm deletion */
3
+ email: string;
4
+ /** Whether the section renders at all. Mirrors the `enable_account_deletion` config flag; defaults to off (opt-in). */
5
+ enabled?: boolean;
6
+ /** Section heading */
7
+ heading?: string;
8
+ /** Section description */
9
+ description?: string;
10
+ /** Label for the button that opens the confirmation dialog */
11
+ deleteButtonLabel?: string;
12
+ /** Confirmation dialog title */
13
+ dialogTitle?: string;
14
+ /** Confirmation dialog description */
15
+ dialogDescription?: string;
16
+ /** Label for the retype-email confirmation input */
17
+ confirmInputLabel?: string;
18
+ /** Label for the destructive confirm button inside the dialog */
19
+ confirmButtonLabel?: string;
20
+ /** Label for the cancel button inside the dialog */
21
+ cancelButtonLabel?: string;
22
+ /** Path to navigate to once the account has been deleted */
23
+ redirectPath?: string;
24
+ };
25
+ /**
26
+ * Danger Zone Section for My Settings
27
+ * Renders a visually distinct destructive section with a "Delete my account" action.
28
+ * Clicking it opens a confirmation dialog that requires the user to re-type their own
29
+ * email address before the destructive button enables. On confirm, calls the
30
+ * account-deletion API route and signs the user out on success.
31
+ * Renders nothing when `enabled` is false (config-gated, default off).
32
+ */
33
+ export declare function DangerZoneSection({ email, enabled, heading, description, deleteButtonLabel, dialogTitle, dialogDescription, confirmInputLabel, confirmButtonLabel, cancelButtonLabel, redirectPath, }: DangerZoneSectionProps): import("react").JSX.Element | null;
34
+ //# sourceMappingURL=danger_zone_section.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"danger_zone_section.d.ts","sourceRoot":"","sources":["../../../../../src/components/layouts/my_settings/components/danger_zone_section.tsx"],"names":[],"mappings":"AA2BA,MAAM,MAAM,sBAAsB,GAAG;IACnC,+FAA+F;IAC/F,KAAK,EAAE,MAAM,CAAC;IACd,uHAAuH;IACvH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,sBAAsB;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0BAA0B;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8DAA8D;IAC9D,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gCAAgC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iEAAiE;IACjE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAGF;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,OAAe,EACf,OAAuB,EACvB,WAAsG,EACtG,iBAAuC,EACvC,WAAoC,EACpC,iBAAiK,EACjK,iBAAwD,EACxD,kBAAoD,EACpD,iBAA4B,EAC5B,YAAiC,GAClC,EAAE,sBAAsB,sCA8JxB"}
@@ -0,0 +1,93 @@
1
+ // file_description: Danger Zone section for My Settings — destructive account deletion gated
2
+ // behind typed-email re-confirmation. Visibility is controlled entirely by the `enabled` prop
3
+ // (threaded down from the `enable_account_deletion` config flag), so this component renders
4
+ // nothing unless explicitly turned on.
5
+ // section: client_directive
6
+ "use client";
7
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
+ // section: imports
9
+ import { useCallback, useMemo, useState } from "react";
10
+ import { useRouter } from "next/navigation";
11
+ import { toast } from "sonner";
12
+ import { AlertTriangle } from "lucide-react";
13
+ import { Button } from "../../../ui/button.js";
14
+ import { Input } from "../../../ui/input.js";
15
+ import { AlertDialog, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "../../../ui/alert-dialog.js";
16
+ import { FormFieldWrapper } from "../../shared/components/form_field_wrapper.js";
17
+ import { trigger_auth_status_refresh } from "../../shared/hooks/use_auth_status.js";
18
+ import { useHazoAuthConfig } from "../../../../contexts/hazo_auth_provider.js";
19
+ // section: component
20
+ /**
21
+ * Danger Zone Section for My Settings
22
+ * Renders a visually distinct destructive section with a "Delete my account" action.
23
+ * Clicking it opens a confirmation dialog that requires the user to re-type their own
24
+ * email address before the destructive button enables. On confirm, calls the
25
+ * account-deletion API route and signs the user out on success.
26
+ * Renders nothing when `enabled` is false (config-gated, default off).
27
+ */
28
+ export function DangerZoneSection({ email, enabled = false, heading = "Danger Zone", description = "Permanently delete your account and all associated data. This action cannot be undone.", deleteButtonLabel = "Delete my account", dialogTitle = "Delete your account?", dialogDescription = "This will permanently delete your account and all associated data. This action cannot be undone. To confirm, type your email address below.", confirmInputLabel = "Type your email address to confirm", confirmButtonLabel = "Permanently delete my account", cancelButtonLabel = "Cancel", redirectPath = "/hazo_auth/login", }) {
29
+ const { apiBasePath } = useHazoAuthConfig();
30
+ const router = useRouter();
31
+ const [dialogOpen, setDialogOpen] = useState(false);
32
+ const [confirmEmail, setConfirmEmail] = useState("");
33
+ const [loading, setLoading] = useState(false);
34
+ /**
35
+ * Compares the typed email against the account email, case-insensitively
36
+ */
37
+ const emailMatches = useMemo(() => {
38
+ const typed = confirmEmail.trim().toLowerCase();
39
+ const actual = (email || "").trim().toLowerCase();
40
+ return typed.length > 0 && typed === actual;
41
+ }, [confirmEmail, email]);
42
+ const resetDialogState = useCallback(() => {
43
+ setConfirmEmail("");
44
+ setLoading(false);
45
+ }, []);
46
+ const handleOpenChange = useCallback((open) => {
47
+ setDialogOpen(open);
48
+ if (!open) {
49
+ resetDialogState();
50
+ }
51
+ }, [resetDialogState]);
52
+ /**
53
+ * Sends the delete request, then signs the user out and redirects on success
54
+ */
55
+ const handleDeleteAccount = useCallback(async () => {
56
+ if (!emailMatches || loading) {
57
+ return;
58
+ }
59
+ setLoading(true);
60
+ try {
61
+ const response = await fetch(`${apiBasePath}/delete_account`, {
62
+ method: "DELETE",
63
+ headers: {
64
+ "Content-Type": "application/json",
65
+ },
66
+ credentials: "include",
67
+ body: JSON.stringify({ confirm_email: confirmEmail }),
68
+ });
69
+ const data = await response.json();
70
+ if (!response.ok || !data.success) {
71
+ const errorMessage = data.error || "Failed to delete account";
72
+ toast.error(errorMessage);
73
+ setLoading(false);
74
+ return;
75
+ }
76
+ toast.success("Your account has been deleted.");
77
+ setDialogOpen(false);
78
+ resetDialogState();
79
+ // Sign the user out client-side and send them away from the now-deleted account
80
+ trigger_auth_status_refresh();
81
+ router.push(redirectPath);
82
+ }
83
+ catch (error) {
84
+ const errorMessage = error instanceof Error ? error.message : "Failed to delete account";
85
+ toast.error(errorMessage);
86
+ setLoading(false);
87
+ }
88
+ }, [emailMatches, loading, apiBasePath, confirmEmail, resetDialogState, router, redirectPath]);
89
+ if (!enabled) {
90
+ return null;
91
+ }
92
+ return (_jsxs("div", { className: "cls_my_settings_danger_zone_section bg-white rounded-lg border border-red-200 p-6", children: [_jsxs("div", { className: "cls_danger_zone_header flex items-center gap-2 mb-2", children: [_jsx(AlertTriangle, { className: "h-5 w-5 text-red-600", "aria-hidden": "true" }), _jsx("h2", { className: "cls_danger_zone_heading text-lg font-semibold text-red-700", children: heading })] }), _jsx("p", { className: "cls_danger_zone_description text-sm text-[var(--hazo-text-muted)] mb-4", children: description }), _jsx("div", { className: "cls_danger_zone_actions flex justify-end", children: _jsx(Button, { type: "button", onClick: () => setDialogOpen(true), variant: "destructive", className: "cls_danger_zone_delete_button", "aria-label": deleteButtonLabel, children: deleteButtonLabel }) }), _jsx(AlertDialog, { open: dialogOpen, onOpenChange: handleOpenChange, children: _jsxs(AlertDialogContent, { className: "cls_delete_account_dialog", children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { className: "cls_delete_account_dialog_title", children: dialogTitle }), _jsx(AlertDialogDescription, { className: "cls_delete_account_dialog_description", children: dialogDescription })] }), _jsx("div", { className: "cls_delete_account_dialog_content py-2", children: _jsx(FormFieldWrapper, { fieldId: "delete-account-confirm-email", label: confirmInputLabel, input: _jsx(Input, { id: "delete-account-confirm-email", type: "email", value: confirmEmail, onChange: (event) => setConfirmEmail(event.target.value), placeholder: email, autoComplete: "off", disabled: loading, "aria-label": confirmInputLabel, className: "cls_delete_account_confirm_input" }) }) }), _jsxs(AlertDialogFooter, { children: [_jsx(Button, { type: "button", onClick: handleDeleteAccount, disabled: !emailMatches || loading, variant: "destructive", className: "cls_delete_account_confirm_button", "aria-label": confirmButtonLabel, children: loading ? "Deleting..." : confirmButtonLabel }), _jsx(Button, { type: "button", onClick: () => handleOpenChange(false), disabled: loading, variant: "outline", className: "cls_delete_account_cancel_button", "aria-label": cancelButtonLabel, children: cancelButtonLabel })] })] }) })] }));
93
+ }
@@ -22,6 +22,11 @@ export type MySettingsLayoutProps = {
22
22
  unauthorizedMessage?: string;
23
23
  loginButtonLabel?: string;
24
24
  loginPath?: string;
25
+ /**
26
+ * Whether the Danger Zone (account deletion) section is shown.
27
+ * Mirrors the `enable_account_deletion` config flag; defaults to off (opt-in).
28
+ */
29
+ enableAccountDeletion?: boolean;
25
30
  heading?: string;
26
31
  subHeading?: string;
27
32
  profilePhotoLabel?: string;
@@ -61,5 +66,5 @@ export type MySettingsLayoutProps = {
61
66
  * @param props - Component props including labels, button colors, password requirements, etc.
62
67
  * @returns My settings layout component
63
68
  */
64
- export default function my_settings_layout({ className, labels, button_colors, password_requirements, profilePicture, userFields, unauthorizedMessage, loginButtonLabel, loginPath, heading, subHeading, profilePhotoLabel, profilePhotoRecommendation, uploadPhotoButtonLabel, removePhotoButtonLabel, profileInformationLabel, passwordLabel, currentPasswordLabel, newPasswordLabel, confirmPasswordLabel, messages, uiSizes, fileTypes, }: MySettingsLayoutProps): import("react").JSX.Element;
69
+ export default function my_settings_layout({ className, labels, button_colors, password_requirements, profilePicture, userFields, unauthorizedMessage, loginButtonLabel, loginPath, enableAccountDeletion, heading, subHeading, profilePhotoLabel, profilePhotoRecommendation, uploadPhotoButtonLabel, removePhotoButtonLabel, profileInformationLabel, passwordLabel, currentPasswordLabel, newPasswordLabel, confirmPasswordLabel, messages, uiSizes, fileTypes, }: MySettingsLayoutProps): import("react").JSX.Element;
65
70
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/layouts/my_settings/index.tsx"],"names":[],"mappings":"AAaA,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EACV,0BAA0B,EAC1B,sBAAsB,EACvB,MAAM,uCAAuC,CAAC;AAQ/C,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,wBAAwB,CAAC;IAClC,aAAa,CAAC,EAAE,sBAAsB,CAAC;IACvC,qBAAqB,EAAE,0BAA0B,CAAC;IAClD,cAAc,EAAE;QACd,kBAAkB,EAAE,OAA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B,EAAE,MAAM,CAAC;QACnC,0BAA0B,EAAE,MAAM,CAAC;QACnC,+BAA+B,EAAE,MAAM,CAAC;QACxC,4BAA4B,EAAE,MAAM,CAAC;KACtC,CAAC;IACF,SAAS,EAAE;QACT,wBAAwB,EAAE,MAAM,EAAE,CAAC;QACnC,wBAAwB,EAAE,MAAM,EAAE,CAAC;KACpC,CAAC;CACH,CAAC;AAGF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,EACzC,SAAS,EACT,MAAM,EACN,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,UAAU,EACV,mBAAkE,EAClE,gBAAgC,EAChC,SAA8B,EAC9B,OAA4B,EAC5B,UAAoE,EACpE,iBAAmC,EACnC,0BAAqE,EACrE,sBAA2C,EAC3C,sBAAiC,EACjC,uBAA+C,EAC/C,aAA0B,EAC1B,oBAAyC,EACzC,gBAAiC,EACjC,oBAAyC,EACzC,QAAQ,EACR,OAAO,EACP,SAAS,GACV,EAAE,qBAAqB,+BAqOvB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/layouts/my_settings/index.tsx"],"names":[],"mappings":"AAcA,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EACV,0BAA0B,EAC1B,sBAAsB,EACvB,MAAM,uCAAuC,CAAC;AAQ/C,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,wBAAwB,CAAC;IAClC,aAAa,CAAC,EAAE,sBAAsB,CAAC;IACvC,qBAAqB,EAAE,0BAA0B,CAAC;IAClD,cAAc,EAAE;QACd,kBAAkB,EAAE,OAAO,CAAC;QAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,cAAc,EAAE,MAAM,CAAC;QACvB,kBAAkB,EAAE,OAAO,CAAC;QAC5B,4BAA4B,EAAE,UAAU,GAAG,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AA4B,EAAE,MAAM,CAAC;KACtC,CAAC;IACF,SAAS,EAAE;QACT,wBAAwB,EAAE,MAAM,EAAE,CAAC;QACnC,wBAAwB,EAAE,MAAM,EAAE,CAAC;KACpC,CAAC;CACH,CAAC;AAGF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,EACzC,SAAS,EACT,MAAM,EACN,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,UAAU,EACV,mBAAkE,EAClE,gBAAgC,EAChC,SAA8B,EAC9B,qBAA6B,EAC7B,OAA4B,EAC5B,UAAoE,EACpE,iBAAmC,EACnC,0BAAqE,EACrE,sBAA2C,EAC3C,sBAAiC,EACjC,uBAA+C,EAC/C,aAA0B,EAC1B,oBAAyC,EACzC,gBAAiC,EACjC,oBAAyC,EACzC,QAAQ,EACR,OAAO,EACP,SAAS,GACV,EAAE,qBAAqB,+BA2OvB"}
@@ -9,6 +9,7 @@ import { ProfilePictureDisplay } from "./components/profile_picture_display.js";
9
9
  import { ProfilePictureDialog } from "./components/profile_picture_dialog.js";
10
10
  import { ConnectedAccountsSection } from "./components/connected_accounts_section.js";
11
11
  import { SetPasswordSection } from "./components/set_password_section.js";
12
+ import { DangerZoneSection } from "./components/danger_zone_section.js";
12
13
  import { UnauthorizedGuard } from "../shared/components/unauthorized_guard.js";
13
14
  import { use_my_settings } from "./hooks/use_my_settings.js";
14
15
  import { resolveMySettingsLabels, resolveMySettingsButtonPalette, } from "./config/my_settings_field_config.js";
@@ -24,7 +25,7 @@ import { cn } from "../../../lib/utils.js";
24
25
  * @param props - Component props including labels, button colors, password requirements, etc.
25
26
  * @returns My settings layout component
26
27
  */
27
- export default function my_settings_layout({ className, labels, button_colors, password_requirements, profilePicture, userFields, unauthorizedMessage = "You must be logged in to access this page.", loginButtonLabel = "Go to login", loginPath = "/hazo_auth/login", heading = "Account Settings", subHeading = "Manage your profile, password, and email preferences.", profilePhotoLabel = "Profile Photo", profilePhotoRecommendation = "Recommended size: 200x200px. JPG, PNG.", uploadPhotoButtonLabel = "Upload New Photo", removePhotoButtonLabel = "Remove", profileInformationLabel = "Profile Information", passwordLabel = "Password", currentPasswordLabel = "Current Password", newPasswordLabel = "New Password", confirmPasswordLabel = "Confirm Password", messages, uiSizes, fileTypes, }) {
28
+ export default function my_settings_layout({ className, labels, button_colors, password_requirements, profilePicture, userFields, unauthorizedMessage = "You must be logged in to access this page.", loginButtonLabel = "Go to login", loginPath = "/hazo_auth/login", enableAccountDeletion = false, heading = "Account Settings", subHeading = "Manage your profile, password, and email preferences.", profilePhotoLabel = "Profile Photo", profilePhotoRecommendation = "Recommended size: 200x200px. JPG, PNG.", uploadPhotoButtonLabel = "Upload New Photo", removePhotoButtonLabel = "Remove", profileInformationLabel = "Profile Information", passwordLabel = "Password", currentPasswordLabel = "Current Password", newPasswordLabel = "New Password", confirmPasswordLabel = "Confirm Password", messages, uiSizes, fileTypes, }) {
28
29
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
29
30
  const resolvedLabels = resolveMySettingsLabels(labels);
30
31
  const resolvedButtonPalette = resolveMySettingsButtonPalette(button_colors);
@@ -34,7 +35,7 @@ export default function my_settings_layout({ className, labels, button_colors, p
34
35
  return (_jsx(UnauthorizedGuard, { message: unauthorizedMessage, loginButtonLabel: loginButtonLabel, loginPath: loginPath, children: _jsxs("div", { className: cn("cls_my_settings_layout flex flex-col gap-6 p-6 w-full", className), children: [_jsxs("div", { className: "cls_my_settings_layout_header flex flex-col gap-2", children: [_jsx("h1", { className: "cls_my_settings_layout_heading text-3xl font-bold text-[var(--hazo-text-primary)]", children: heading }), _jsx("p", { className: "cls_my_settings_layout_subheading text-[var(--hazo-text-muted)]", children: subHeading })] }), _jsxs("div", { className: "cls_my_settings_layout_profile_photo_section bg-white rounded-lg border border-[var(--hazo-border)] p-6", children: [_jsx("h2", { className: "cls_my_settings_layout_section_heading text-lg font-semibold text-[var(--hazo-text-primary)] mb-4", children: profilePhotoLabel }), _jsx("div", { className: "cls_my_settings_layout_profile_photo_content flex flex-col items-center", children: _jsxs("div", { className: "cls_my_settings_layout_profile_photo_display relative", children: [_jsx(ProfilePictureDisplay, { profilePictureUrl: settings.profilePictureUrl, name: settings.name, email: settings.email, onEdit: settings.handleProfilePictureEdit }), _jsxs("div", { className: "cls_my_settings_layout_profile_photo_actions absolute left-0 right-0 flex items-center justify-between px-2", style: { bottom: '-20px' }, children: [_jsx(Button, { type: "button", onClick: settings.handleProfilePictureEdit, disabled: settings.loading, variant: "ghost", size: "icon", className: "cls_my_settings_layout_upload_photo_button", "aria-label": uploadPhotoButtonLabel, children: _jsx(Pencil, { className: "h-4 w-4", "aria-hidden": "true" }) }), _jsx(Button, { type: "button", onClick: settings.handleProfilePictureRemove, disabled: settings.loading || !settings.profilePictureUrl, variant: "ghost", size: "icon", className: "cls_my_settings_layout_remove_photo_button text-red-600 hover:text-red-700 hover:bg-red-50", "aria-label": removePhotoButtonLabel, children: _jsx(Trash2, { className: "h-4 w-4", "aria-hidden": "true" }) })] })] }) })] }), _jsxs("div", { className: "cls_my_settings_layout_profile_information_section bg-white rounded-lg border border-[var(--hazo-border)] p-6", children: [_jsx("h2", { className: "cls_my_settings_layout_section_heading text-lg font-semibold text-[var(--hazo-text-primary)] mb-4", children: profileInformationLabel }), _jsxs("div", { className: "cls_my_settings_layout_profile_information_fields grid grid-cols-1 md:grid-cols-2 gap-6", children: [userFields.show_name_field && (_jsx(EditableField, { label: "Full Name", value: settings.name, type: "text", placeholder: "Enter your full name", onSave: settings.handleNameSave, validation: validateName, disabled: settings.loading, ariaLabel: "Full name input field" })), userFields.show_email_field && (_jsx(EditableField, { label: "Email Address", value: settings.email, type: "email", placeholder: "Enter your email address", onSave: settings.handleEmailSave, validation: validateEmail, disabled: settings.loading, ariaLabel: "Email address input field" }))] })] }), userFields.show_password_field && settings.hasPassword && (_jsxs("div", { className: "cls_my_settings_layout_password_section bg-white rounded-lg border border-[var(--hazo-border)] p-6", children: [_jsx("h2", { className: "cls_my_settings_layout_section_heading text-lg font-semibold text-[var(--hazo-text-primary)] mb-4", children: passwordLabel }), _jsxs("div", { className: "cls_my_settings_layout_password_fields flex flex-col gap-6", children: [_jsx(FormFieldWrapper, { fieldId: "current-password", label: currentPasswordLabel, input: _jsx(PasswordField, { inputId: "current-password", ariaLabel: currentPasswordLabel, value: ((_a = settings.passwordFields) === null || _a === void 0 ? void 0 : _a.currentPassword) || "", placeholder: "Enter your current password", autoComplete: "current-password", isVisible: ((_b = settings.passwordFields) === null || _b === void 0 ? void 0 : _b.currentPasswordVisible) || false, onChange: (value) => settings.handlePasswordFieldChange("currentPassword", value), onToggleVisibility: () => settings.togglePasswordVisibility("currentPassword"), errorMessage: (_d = (_c = settings.passwordFields) === null || _c === void 0 ? void 0 : _c.errors) === null || _d === void 0 ? void 0 : _d.currentPassword }) }), _jsxs("div", { className: "cls_my_settings_layout_password_fields_row grid grid-cols-1 md:grid-cols-2 gap-6", children: [_jsx(FormFieldWrapper, { fieldId: "new-password", label: newPasswordLabel, input: _jsx(PasswordField, { inputId: "new-password", ariaLabel: newPasswordLabel, value: ((_e = settings.passwordFields) === null || _e === void 0 ? void 0 : _e.newPassword) || "", placeholder: "Enter your new password", autoComplete: "new-password", isVisible: ((_f = settings.passwordFields) === null || _f === void 0 ? void 0 : _f.newPasswordVisible) || false, onChange: (value) => settings.handlePasswordFieldChange("newPassword", value), onToggleVisibility: () => settings.togglePasswordVisibility("newPassword"), errorMessage: (_h = (_g = settings.passwordFields) === null || _g === void 0 ? void 0 : _g.errors) === null || _h === void 0 ? void 0 : _h.newPassword }) }), _jsx(FormFieldWrapper, { fieldId: "confirm-password", label: confirmPasswordLabel, input: _jsx(PasswordField, { inputId: "confirm-password", ariaLabel: confirmPasswordLabel, value: ((_j = settings.passwordFields) === null || _j === void 0 ? void 0 : _j.confirmPassword) || "", placeholder: "Confirm your new password", autoComplete: "new-password", isVisible: ((_k = settings.passwordFields) === null || _k === void 0 ? void 0 : _k.confirmPasswordVisible) || false, onChange: (value) => settings.handlePasswordFieldChange("confirmPassword", value), onToggleVisibility: () => settings.togglePasswordVisibility("confirmPassword"), errorMessage: (_m = (_l = settings.passwordFields) === null || _l === void 0 ? void 0 : _l.errors) === null || _m === void 0 ? void 0 : _m.confirmPassword }) })] })] }), _jsx("div", { className: "cls_my_settings_layout_password_actions flex justify-end mt-4", children: _jsx(Button, { type: "button", onClick: settings.handlePasswordSave, disabled: settings.loading || settings.isPasswordSaveDisabled, className: "cls_my_settings_layout_save_password_button", style: {
35
36
  backgroundColor: resolvedButtonPalette.submitBackground,
36
37
  color: resolvedButtonPalette.submitText,
37
- }, "aria-label": "Save password", children: "Save Password" }) })] })), !settings.hasPassword && settings.googleConnected && (_jsx(SetPasswordSection, { passwordRequirements: password_requirements, onPasswordSet: settings.refreshUserData, parentLoading: settings.loading })), _jsx(ConnectedAccountsSection, { googleConnected: settings.googleConnected || false, email: settings.email, loading: settings.loading }), _jsx(ProfilePictureDialog, { open: settings.profilePictureDialogOpen, onOpenChange: (open) => {
38
+ }, "aria-label": "Save password", children: "Save Password" }) })] })), !settings.hasPassword && settings.googleConnected && (_jsx(SetPasswordSection, { passwordRequirements: password_requirements, onPasswordSet: settings.refreshUserData, parentLoading: settings.loading })), _jsx(ConnectedAccountsSection, { googleConnected: settings.googleConnected || false, email: settings.email, loading: settings.loading }), _jsx(DangerZoneSection, { enabled: enableAccountDeletion, email: settings.email }), _jsx(ProfilePictureDialog, { open: settings.profilePictureDialogOpen, onOpenChange: (open) => {
38
39
  if (open) {
39
40
  settings.handleProfilePictureEdit();
40
41
  }
@@ -1,4 +1,4 @@
1
- // file_description: dialog component shown when a fetch response returns error.code === 'PERMISSION_DENIED'
1
+ // file_description: dialog component shown when a fetch response returns error.code === 'FORBIDDEN' (or legacy 'PERMISSION_DENIED')
2
2
  // Probes hazo_ui at mount time (it's a peer dep) and falls back to plain HTML if unavailable.
3
3
  'use client';
4
4
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { type VariantProps } from "class-variance-authority";
3
3
  declare const buttonVariants: (props?: ({
4
- variant?: "link" | "default" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
4
+ variant?: "default" | "link" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
5
5
  size?: "default" | "sm" | "lg" | "icon" | null | undefined;
6
6
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
7
7
  export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
@@ -0,0 +1,5 @@
1
+ export { use_auth_status, trigger_auth_status_refresh } from "./components/layouts/shared/hooks/use_auth_status.js";
2
+ export { use_hazo_auth, trigger_hazo_auth_refresh } from "./components/layouts/shared/hooks/use_hazo_auth.js";
3
+ export type { UseHazoAuthOptions, UseHazoAuthResult } from "./components/layouts/shared/hooks/use_hazo_auth";
4
+ export * from "./lib/auth/auth_types.js";
5
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAC;AACjH,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AAC3G,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AAI7G,cAAc,uBAAuB,CAAC"}
package/dist/hooks.js ADDED
@@ -0,0 +1,29 @@
1
+ // file_description: hooks-only client entry point — auth state without any component code
2
+ //
3
+ // USAGE:
4
+ // import { use_hazo_auth } from "hazo_auth/hooks";
5
+ //
6
+ // WHY THIS EXISTS (separate from "hazo_auth/client"):
7
+ // `hazo_auth/client` re-exports the package's entire component surface via
8
+ // `export * from "./components/index.js"` — which transitively pulls in
9
+ // ProfilePicMenu -> RolesMatrix (the whole user-management surface), the
10
+ // shadcn-derived UI kit, hazo_ui, and peer packages like sonner and the
11
+ // @radix-ui/* set. Bundlers cannot tree-shake most of that away, because these
12
+ // are "use client" modules with side effects.
13
+ //
14
+ // That is fine for a page that renders an auth layout. It is very expensive for
15
+ // a consuming app that only wants to know "is someone signed in?" in, say, a
16
+ // site header or a save button that renders on every page — a consumer doing
17
+ // exactly that measured its landing-page JS grow by more than an order of
18
+ // magnitude purely from reaching for `use_hazo_auth`.
19
+ //
20
+ // This entry point exposes the auth-state hooks and nothing else, so
21
+ // "read the session" costs a fetch wrapper rather than the whole UI kit.
22
+ // Components still come from "hazo_auth/client" (or a narrower subpath), and
23
+ // are best loaded lazily when they are actually needed.
24
+ // section: auth_state_hook_exports
25
+ export { use_auth_status, trigger_auth_status_refresh } from "./components/layouts/shared/hooks/use_auth_status.js";
26
+ export { use_hazo_auth, trigger_hazo_auth_refresh } from "./components/layouts/shared/hooks/use_hazo_auth.js";
27
+ // section: type_exports
28
+ // Type definitions are erased at runtime, so they cost nothing to re-export.
29
+ export * from "./lib/auth/auth_types.js";
@@ -1 +1 @@
1
- {"version":3,"file":"with_auth.server.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/with_auth.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAGrB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACrB,MAAM,cAAc,CAAC;AAItB;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,IAAI,CAAC;IACpB,IAAI,EAAE,YAAY,CAAC;IACnB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B,YAAY,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O,EAAE,mBAAmB,CAAC,OAAO,CAAC,EACrC,OAAO,GAAE,iBAAsB,GAC9B,CACD,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,KAC5B,OAAO,CAAC,YAAY,CAAC,CAazB;AAID;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,uBAAuB,EAC7B,UAAU,EAAE,MAAM,GACjB,OAAO,CAET;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,uBAAuB,EAC7B,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAET;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,uBAAuB,EAC7B,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAET;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,uBAAuB,EAC7B,UAAU,EAAE,MAAM,GACjB,IAAI,CAQN;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,uBAAuB,EAC7B,WAAW,EAAE,MAAM,EAAE,GACpB,IAAI,CASN"}
@@ -5,20 +5,52 @@ import "server-only";
5
5
  import { NextResponse } from "next/server";
6
6
  import { hazo_get_tenant_auth } from "./hazo_get_tenant_auth.server.js";
7
7
  import { HazoAuthError, PermissionError, } from "./auth_types.js";
8
+ import { buildForbiddenResponse, buildDenialPayloadFromRequest, getPermissionDeniedHandler, } from "./with_permission_issue_capture.server.js";
9
+ import { get_app_permission_descriptions } from "../app_permissions_config.server.js";
8
10
  // section: error_response_helper
11
+ /** Converts get_app_permission_descriptions()'s Map into the Record shape PermissionDeniedPayload expects. */
12
+ function descriptions_map_to_record(map) {
13
+ return Object.fromEntries(map);
14
+ }
15
+ /**
16
+ * Fire the denial escalation handler best-effort (never awaited, never
17
+ * throws), then return the canonical FORBIDDEN envelope.
18
+ */
19
+ async function respond_permission_denied(payload) {
20
+ try {
21
+ const handler = getPermissionDeniedHandler();
22
+ if (handler) {
23
+ // fire-and-forget; escalation must never delay or fail the 403
24
+ Promise.resolve()
25
+ .then(() => handler(payload))
26
+ .catch(() => {
27
+ /* swallow */
28
+ });
29
+ }
30
+ }
31
+ catch (_a) {
32
+ /* swallow */
33
+ }
34
+ return (await buildForbiddenResponse(payload));
35
+ }
9
36
  /**
10
37
  * Converts caught errors into appropriate NextResponse JSON responses
11
38
  */
12
- function handle_auth_error(error) {
39
+ async function handle_auth_error(error, request) {
40
+ var _a, _b, _c, _d, _e;
13
41
  if (error instanceof HazoAuthError) {
14
42
  return NextResponse.json({ error: error.message, code: error.code }, { status: error.status_code });
15
43
  }
16
44
  if (error instanceof PermissionError) {
17
- return NextResponse.json({
18
- error: error.message,
19
- code: "PERMISSION_DENIED",
20
- missing_permissions: error.missing_permissions,
21
- }, { status: 403 });
45
+ const descriptions = get_app_permission_descriptions((_a = error.missing_permissions) !== null && _a !== void 0 ? _a : []);
46
+ const payload = buildDenialPayloadFromRequest(request, {
47
+ user_id: "",
48
+ missing_permissions: (_b = error.missing_permissions) !== null && _b !== void 0 ? _b : [],
49
+ required_permissions: (_d = (_c = error.required_permissions) !== null && _c !== void 0 ? _c : error.missing_permissions) !== null && _d !== void 0 ? _d : [],
50
+ permission_descriptions: descriptions_map_to_record(descriptions),
51
+ user_permissions: (_e = error.user_permissions) !== null && _e !== void 0 ? _e : [],
52
+ });
53
+ return respond_permission_denied(payload);
22
54
  }
23
55
  console.error("Unexpected error in route handler:", error);
24
56
  return NextResponse.json({ error: "Internal server error" }, { status: 500 });
@@ -34,7 +66,7 @@ async function resolve_params(context) {
34
66
  }
35
67
  export function withAuth(handler, options = {}) {
36
68
  return async (request, context) => {
37
- var _a;
69
+ var _a, _b, _c, _d, _e;
38
70
  try {
39
71
  const auth = await hazo_get_tenant_auth(request, options);
40
72
  if (!auth.authenticated) {
@@ -42,12 +74,16 @@ export function withAuth(handler, options = {}) {
42
74
  }
43
75
  // Check permissions if required_permissions were specified
44
76
  if (((_a = options.required_permissions) === null || _a === void 0 ? void 0 : _a.length) && !auth.permission_ok) {
45
- return NextResponse.json(Object.assign({ error: "Insufficient permissions", code: "PERMISSION_DENIED", missing_permissions: auth.missing_permissions }, (process.env.NODE_ENV === "development" && {
46
- debug: {
47
- user_permissions: auth.permissions,
48
- required_permissions: options.required_permissions,
49
- },
50
- })), { status: 403 });
77
+ const descriptions = get_app_permission_descriptions((_b = auth.missing_permissions) !== null && _b !== void 0 ? _b : []);
78
+ const payload = buildDenialPayloadFromRequest(request, {
79
+ user_id: (_d = (_c = auth.user) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : "",
80
+ scope_id: options.scope_id,
81
+ missing_permissions: (_e = auth.missing_permissions) !== null && _e !== void 0 ? _e : [],
82
+ required_permissions: options.required_permissions,
83
+ permission_descriptions: descriptions_map_to_record(descriptions),
84
+ user_permissions: auth.permissions,
85
+ });
86
+ return respond_permission_denied(payload);
51
87
  }
52
88
  // Check tenant requirement
53
89
  if (options.require_tenant && !auth.organization) {
@@ -61,7 +97,7 @@ export function withAuth(handler, options = {}) {
61
97
  return await handler(request, auth, params);
62
98
  }
63
99
  catch (error) {
64
- return handle_auth_error(error);
100
+ return await handle_auth_error(error, request);
65
101
  }
66
102
  };
67
103
  }
@@ -90,7 +126,7 @@ export function withOptionalAuth(handler, options = {}) {
90
126
  return await handler(request, auth, params);
91
127
  }
92
128
  catch (error) {
93
- return handle_auth_error(error);
129
+ return await handle_auth_error(error, request);
94
130
  }
95
131
  };
96
132
  }
@@ -1,4 +1,5 @@
1
1
  import "server-only";
2
+ import type { NextResponse } from "next/server";
2
3
  export type CookiesConfig = {
3
4
  /** Prefix for all hazo_auth cookies (e.g., "myapp_" results in "myapp_hazo_auth_session") */
4
5
  cookie_prefix: string;
@@ -43,4 +44,23 @@ export declare function get_cached_cookies_config(): CookiesConfig;
43
44
  * Clears the cached config (useful for testing)
44
45
  */
45
46
  export declare function clear_cookies_config_cache(): void;
47
+ /**
48
+ * Clears the three core hazo_auth session cookies (USER_EMAIL, USER_ID, SESSION)
49
+ * from a response, honoring the configured cookie prefix/domain. This is the same
50
+ * clearing logic used by the logout route; reuse it anywhere a session needs to be
51
+ * torn down (e.g. self-service account deletion) instead of re-implementing it.
52
+ * @param response - NextResponse object to clear cookies from
53
+ * @returns The same response, with cleared cookies (for chaining)
54
+ */
55
+ export declare function clear_session_cookies<T extends NextResponse>(response: T): T;
56
+ /**
57
+ * Clears the NextAuth.js cookies used by the Google OAuth flow (session token,
58
+ * CSRF token, callback URL — plus their `__Secure-`/`__Host-` production variants)
59
+ * from a response. This is the same clearing logic used by the logout route; reuse
60
+ * it anywhere a NextAuth-backed session needs to be torn down (e.g. self-service
61
+ * account deletion) instead of re-implementing it.
62
+ * @param response - NextResponse object to clear cookies from
63
+ * @returns The same response, with cleared cookies (for chaining)
64
+ */
65
+ export declare function clear_nextauth_cookies<T extends NextResponse>(response: T): T;
46
66
  //# sourceMappingURL=cookies_config.server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cookies_config.server.d.ts","sourceRoot":"","sources":["../../src/lib/cookies_config.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAMrB,MAAM,MAAM,aAAa,GAAG;IAC1B,6FAA6F;IAC7F,aAAa,EAAE,MAAM,CAAC;IACtB,6EAA6E;IAC7E,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAYF,eAAO,MAAM,iBAAiB;;;;;;;;CAQpB,CAAC;AAGX;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,aAAa,CAuBlD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAQzG;AAKD;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,aAAa,CAKzD;AAED;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD"}
1
+ {"version":3,"file":"cookies_config.server.d.ts","sourceRoot":"","sources":["../../src/lib/cookies_config.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKhD,MAAM,MAAM,aAAa,GAAG;IAC1B,6FAA6F;IAC7F,aAAa,EAAE,MAAM,CAAC;IACtB,6EAA6E;IAC7E,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAYF,eAAO,MAAM,iBAAiB;;;;;;;;CAQpB,CAAC;AAGX;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,aAAa,CAuBlD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAQzG;AAKD;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,aAAa,CAKzD;AAED;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,YAAY,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAW5E;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,YAAY,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAiB7E"}
@@ -86,3 +86,46 @@ export function get_cached_cookies_config() {
86
86
  export function clear_cookies_config_cache() {
87
87
  cached_config = null;
88
88
  }
89
+ /**
90
+ * Clears the three core hazo_auth session cookies (USER_EMAIL, USER_ID, SESSION)
91
+ * from a response, honoring the configured cookie prefix/domain. This is the same
92
+ * clearing logic used by the logout route; reuse it anywhere a session needs to be
93
+ * torn down (e.g. self-service account deletion) instead of re-implementing it.
94
+ * @param response - NextResponse object to clear cookies from
95
+ * @returns The same response, with cleared cookies (for chaining)
96
+ */
97
+ export function clear_session_cookies(response) {
98
+ const clear_cookie_options = get_cookie_options({
99
+ expires: new Date(0),
100
+ path: "/",
101
+ });
102
+ response.cookies.set(get_cookie_name(BASE_COOKIE_NAMES.USER_EMAIL), "", clear_cookie_options);
103
+ response.cookies.set(get_cookie_name(BASE_COOKIE_NAMES.USER_ID), "", clear_cookie_options);
104
+ response.cookies.set(get_cookie_name(BASE_COOKIE_NAMES.SESSION), "", clear_cookie_options);
105
+ return response;
106
+ }
107
+ /**
108
+ * Clears the NextAuth.js cookies used by the Google OAuth flow (session token,
109
+ * CSRF token, callback URL — plus their `__Secure-`/`__Host-` production variants)
110
+ * from a response. This is the same clearing logic used by the logout route; reuse
111
+ * it anywhere a NextAuth-backed session needs to be torn down (e.g. self-service
112
+ * account deletion) instead of re-implementing it.
113
+ * @param response - NextResponse object to clear cookies from
114
+ * @returns The same response, with cleared cookies (for chaining)
115
+ */
116
+ export function clear_nextauth_cookies(response) {
117
+ const clear_cookie_options = {
118
+ expires: new Date(0),
119
+ path: "/",
120
+ };
121
+ response.cookies.set("next-auth.session-token", "", clear_cookie_options);
122
+ response.cookies.set("next-auth.csrf-token", "", clear_cookie_options);
123
+ response.cookies.set("next-auth.callback-url", "", clear_cookie_options);
124
+ // Also clear secure cookie variants (used in production with HTTPS)
125
+ response.cookies.set("__Secure-next-auth.session-token", "", clear_cookie_options);
126
+ response.cookies.set("__Secure-next-auth.csrf-token", "", clear_cookie_options);
127
+ response.cookies.set("__Secure-next-auth.callback-url", "", clear_cookie_options);
128
+ // Host-prefixed variants (for some NextAuth configurations)
129
+ response.cookies.set("__Host-next-auth.csrf-token", "", clear_cookie_options);
130
+ return response;
131
+ }
@@ -36,6 +36,8 @@ export type MySettingsConfig = {
36
36
  unauthorizedMessage?: string;
37
37
  loginButtonLabel?: string;
38
38
  loginPath?: string;
39
+ /** Opt-in self-service account deletion (Danger Zone). Default: false. */
40
+ enableAccountDeletion: boolean;
39
41
  messages: {
40
42
  photo_upload_disabled_message: string;
41
43
  gravatar_setup_message: string;
@@ -1 +1 @@
1
- {"version":3,"file":"my_settings_config.server.d.ts","sourceRoot":"","sources":["../../src/lib/my_settings_config.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAYrB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE;QACV,eAAe,EAAE,OAAO,CAAC;QACzB,gBAAgB,EAAE,OAAO,CAAC;QAC1B,mBAAmB,EAAE,OAAO,CAAC;KAC9B,CAAC;IACF,oBAAoB,EAAE;QACpB,cAAc,EAAE,MAAM,CAAC;QACvB,iBAAiB,EAAE,OAAO,CAAC;QAC3B,iBAAiB,EAAE,OAAO,CAAC;QAC3B,cAAc,EAAE,OAAO,CAAC;QACxB,eAAe,EAAE,OAAO,CAAC;KAC1B,CAAC;IACF,cAAc,EAAE;QACd,kBAAkB,EAAE,OAAO,CAAC;QAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,cAAc,EAAE,MAAM,CAAC;QACvB,kBAAkB,EAAE,OAAO,CAAC;QAC5B,4BAA4B,EAAE,UAAU,GAAG,SAAS,CAAC;QACrD,4BAA4B,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;QACtD,kBAAkB,EAAE,MAAM,CAAC;KAC5B,CAAC;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE;QACR,6BAA6B,EAAE,MAAM,CAAC;QACtC,sBAAsB,EAAE,MAAM,CAAC;QAC/B,2BAA2B,EAAE,MAAM,CAAC;QACpC,uBAAuB,EAAE,MAAM,CAAC;KACjC,CAAC;IACF,OAAO,EAAE;QACP,aAAa,EAAE,MAAM,CAAC;QACtB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,yBAAyB,EAAE,MAAM,CAAC;QAClC,uBAAuB,EAAE,MAAM,CAAC;QAChC,0BAA0B,EAAE,MAAM,CAAC;QACnC,0BAA0B,EAAE,MAAM,CAAC;QACnC,+BAA+B,EAAE,MAAM,CAAC;QACxC,4BAA4B,EAAE,MAAM,CAAC;KACtC,CAAC;IACF,SAAS,EAAE;QACT,wBAAwB,EAAE,MAAM,EAAE,CAAC;QACnC,wBAAwB,EAAE,MAAM,EAAE,CAAC;KACpC,CAAC;CACH,CAAC;AAGF;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAyDzD"}
1
+ {"version":3,"file":"my_settings_config.server.d.ts","sourceRoot":"","sources":["../../src/lib/my_settings_config.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAYrB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE;QACV,eAAe,EAAE,OAAO,CAAC;QACzB,gBAAgB,EAAE,OAAO,CAAC;QAC1B,mBAAmB,EAAE,OAAO,CAAC;KAC9B,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pC,uBAAuB,EAAE,MAAM,CAAC;KACjC,CAAC;IACF,OAAO,EAAE;QACP,aAAa,EAAE,MAAM,CAAC;QACtB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,yBAAyB,EAAE,MAAM,CAAC;QAClC,uBAAuB,EAAE,MAAM,CAAC;QAChC,0BAA0B,EAAE,MAAM,CAAC;QACnC,0BAA0B,EAAE,MAAM,CAAC;QACnC,+BAA+B,EAAE,MAAM,CAAC;QACxC,4BAA4B,EAAE,MAAM,CAAC;KACtC,CAAC;IACF,SAAS,EAAE;QACT,wBAAwB,EAAE,MAAM,EAAE,CAAC;QACnC,wBAAwB,EAAE,MAAM,EAAE,CAAC;KACpC,CAAC;CACH,CAAC;AAGF;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CA2DzD"}
@@ -2,7 +2,7 @@
2
2
  // section: server-only-guard
3
3
  import "server-only";
4
4
  // section: imports
5
- import { get_config_value } from "./config/config_loader.server.js";
5
+ import { get_config_value, get_config_boolean } from "./config/config_loader.server.js";
6
6
  import { get_user_fields_config } from "./user_fields_config.server.js";
7
7
  import { get_password_requirements_config } from "./password_requirements_config.server.js";
8
8
  import { get_profile_picture_config } from "./profile_picture_config.server.js";
@@ -43,6 +43,7 @@ export function get_my_settings_config() {
43
43
  const unauthorizedMessage = get_config_value(section, "unauthorized_message", "You must be logged in to access this page.");
44
44
  const loginButtonLabel = get_config_value(section, "login_button_label", "Go to login");
45
45
  const loginPath = get_config_value(section, "login_path", "/hazo_auth/login");
46
+ const enableAccountDeletion = get_config_boolean(section, "enable_account_deletion", false);
46
47
  return {
47
48
  userFields,
48
49
  passwordRequirements,
@@ -62,6 +63,7 @@ export function get_my_settings_config() {
62
63
  unauthorizedMessage,
63
64
  loginButtonLabel,
64
65
  loginPath,
66
+ enableAccountDeletion,
65
67
  messages,
66
68
  uiSizes,
67
69
  fileTypes,
@@ -0,0 +1,22 @@
1
+ export type AccountDeletionResult = {
2
+ success: boolean;
3
+ error?: string;
4
+ };
5
+ /**
6
+ * Hard-deletes the caller's own `hazo_users` row.
7
+ *
8
+ * Child rows cascade automatically via `ON DELETE CASCADE` foreign keys
9
+ * (hazo_refresh_tokens, hazo_user_scopes, hazo_user_relationships,
10
+ * hazo_email_otps, hazo_legal_acceptances, hazo_google_oauth_tokens,
11
+ * hazo_user_roles) — no manual cleanup needed. A few "created by" /
12
+ * "managed by" references (hazo_users.managed_by_user_id,
13
+ * hazo_invitations.invited_by, hazo_legal_doc_versions.published_by_user_id)
14
+ * intentionally use `ON DELETE SET NULL` instead of CASCADE, by design —
15
+ * they preserve audit/history/relationship rows rather than deleting them,
16
+ * so they likewise require no manual cleanup here.
17
+ *
18
+ * @param user_id - The authenticated caller's own user ID (never another user's)
19
+ * @returns AccountDeletionResult with success status or error
20
+ */
21
+ export declare function delete_own_account(user_id: string): Promise<AccountDeletionResult>;
22
+ //# sourceMappingURL=account_deletion_service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account_deletion_service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/account_deletion_service.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAGF;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,qBAAqB,CAAC,CAiChC"}