hazo_auth 10.9.0 → 10.14.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 (60) hide show
  1. package/README.md +52 -0
  2. package/cli-src/cli/generate.ts +1 -0
  3. package/cli-src/lib/auth/hazo_get_tenant_auth.server.ts +12 -3
  4. package/cli-src/lib/auth/index.ts +2 -0
  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/otp_config.server.ts +11 -0
  8. package/cli-src/lib/services/account_deletion_service.ts +67 -0
  9. package/cli-src/lib/services/index.ts +1 -0
  10. package/config/hazo_auth_config.example.ini +33 -19
  11. package/dist/cli/generate.d.ts.map +1 -1
  12. package/dist/cli/generate.js +1 -0
  13. package/dist/components/layouts/my_settings/components/danger_zone_section.d.ts +34 -0
  14. package/dist/components/layouts/my_settings/components/danger_zone_section.d.ts.map +1 -0
  15. package/dist/components/layouts/my_settings/components/danger_zone_section.js +93 -0
  16. package/dist/components/layouts/my_settings/index.d.ts +6 -1
  17. package/dist/components/layouts/my_settings/index.d.ts.map +1 -1
  18. package/dist/components/layouts/my_settings/index.js +3 -2
  19. package/dist/components/ui/button.d.ts +1 -1
  20. package/dist/hooks.d.ts +5 -0
  21. package/dist/hooks.d.ts.map +1 -0
  22. package/dist/hooks.js +29 -0
  23. package/dist/lib/auth/hazo_get_tenant_auth.server.d.ts +10 -0
  24. package/dist/lib/auth/hazo_get_tenant_auth.server.d.ts.map +1 -1
  25. package/dist/lib/auth/hazo_get_tenant_auth.server.js +11 -3
  26. package/dist/lib/auth/index.d.ts +1 -1
  27. package/dist/lib/auth/index.d.ts.map +1 -1
  28. package/dist/lib/auth/index.js +1 -1
  29. package/dist/lib/cookies_config.server.d.ts +20 -0
  30. package/dist/lib/cookies_config.server.d.ts.map +1 -1
  31. package/dist/lib/cookies_config.server.js +43 -0
  32. package/dist/lib/my_settings_config.server.d.ts +2 -0
  33. package/dist/lib/my_settings_config.server.d.ts.map +1 -1
  34. package/dist/lib/my_settings_config.server.js +3 -1
  35. package/dist/lib/otp_config.server.d.ts +6 -0
  36. package/dist/lib/otp_config.server.d.ts.map +1 -1
  37. package/dist/lib/otp_config.server.js +7 -0
  38. package/dist/lib/services/account_deletion_service.d.ts +22 -0
  39. package/dist/lib/services/account_deletion_service.d.ts.map +1 -0
  40. package/dist/lib/services/account_deletion_service.js +55 -0
  41. package/dist/lib/services/index.d.ts +1 -0
  42. package/dist/lib/services/index.d.ts.map +1 -1
  43. package/dist/lib/services/index.js +1 -0
  44. package/dist/page_components/my_settings.d.ts +6 -1
  45. package/dist/page_components/my_settings.d.ts.map +1 -1
  46. package/dist/page_components/my_settings.js +2 -2
  47. package/dist/server/routes/delete_account.d.ts +17 -0
  48. package/dist/server/routes/delete_account.d.ts.map +1 -0
  49. package/dist/server/routes/delete_account.js +107 -0
  50. package/dist/server/routes/index.d.ts +1 -0
  51. package/dist/server/routes/index.d.ts.map +1 -1
  52. package/dist/server/routes/index.js +1 -0
  53. package/dist/server/routes/logout.d.ts.map +1 -1
  54. package/dist/server/routes/logout.js +4 -40
  55. package/dist/server_pages/my_settings.d.ts.map +1 -1
  56. package/dist/server_pages/my_settings.js +1 -1
  57. package/dist/server_pages/otp.d.ts +12 -1
  58. package/dist/server_pages/otp.d.ts.map +1 -1
  59. package/dist/server_pages/otp.js +12 -2
  60. package/package.json +35 -89
package/README.md CHANGED
@@ -3097,6 +3097,46 @@ When `enabled = false` (default), all relationship routes return 404, email rema
3097
3097
 
3098
3098
  ---
3099
3099
 
3100
+ ## Self-Service Account Deletion
3101
+
3102
+ hazo_auth supports letting an authenticated user permanently (hard) delete their own account — the deletion cascades to all related rows (scopes, invitations, tokens, etc.) via `delete_own_account`. A "Danger Zone" section is available in the My Settings layout to trigger this from the UI.
3103
+
3104
+ ### Enabling
3105
+
3106
+ The feature is opt-in and **off by default**. Add to your `hazo_auth_config.ini`:
3107
+
3108
+ ```ini
3109
+ [hazo_auth__my_settings_layout]
3110
+ enable_account_deletion = true
3111
+ ```
3112
+
3113
+ ### API
3114
+
3115
+ | Method | Endpoint | Description |
3116
+ |--------|----------|-------------|
3117
+ | DELETE | `/api/hazo_auth/delete_account` | Hard-delete the caller's own account (body: `{ confirm_email }`) |
3118
+
3119
+ The caller must re-type their own email address as confirmation. `confirm_email` is matched against the authenticated user's email **case-insensitively**.
3120
+
3121
+ **Responses:**
3122
+
3123
+ | Status | Body | When |
3124
+ |--------|------|------|
3125
+ | 200 | `{ success: true, message: "Account deleted successfully" }` | Account deleted; session cookies (hazo_auth + NextAuth/OAuth) are cleared |
3126
+ | 401 | `{ error: "Authentication required" }` | No authenticated session |
3127
+ | 403 | `{ error: "Account deletion is not enabled" }` | `enable_account_deletion` is `false` (the default) |
3128
+ | 400 | `{ error: "Confirmation email does not match your account email" }` (or missing `confirm_email`) | Confirmation check failed |
3129
+ | 400 | `{ error: <service error> }` | `delete_own_account` reported failure |
3130
+ | 500 | `{ error: "Failed to delete account. Please try again." }` | Unexpected error |
3131
+
3132
+ On success, the route clears the three core hazo_auth session cookies as well as the NextAuth/Google-OAuth cookie set, so a deleted Google-OAuth user isn't left holding a live `next-auth.session-token`.
3133
+
3134
+ ### Feature Gating
3135
+
3136
+ When `enable_account_deletion = false` (default), `DELETE /api/hazo_auth/delete_account` always returns 403 and existing behavior is completely unchanged.
3137
+
3138
+ ---
3139
+
3100
3140
  ## User Profile Service
3101
3141
 
3102
3142
  The `hazo_auth` package provides a batch user profile retrieval service for applications that need basic user information, such as chat applications or user lists.
@@ -3251,6 +3291,18 @@ export default function Page(props) { return <OTPPage {...props} />; }
3251
3291
 
3252
3292
  Enable in config: `[hazo_auth__otp] enable_email_otp = true`. Run `npx hazo_auth migrate migrations/015_email_otp.sql`.
3253
3293
 
3294
+ The visual panel image defaults to `/hazo_auth/images/login_default.jpg` (what `npx hazo_auth init` copies into `public/`). Override it per-page or in config — apps serving the packaged images from the generated `/api/hazo_auth/assets/[name]` route want the latter path:
3295
+
3296
+ ```tsx
3297
+ <OTPPage {...props} image_src="/api/hazo_auth/assets/login_default.jpg" />
3298
+ ```
3299
+
3300
+ ```ini
3301
+ [hazo_auth__otp]
3302
+ otp_image_src = /api/hazo_auth/assets/login_default.jpg
3303
+ otp_image_alt = Sign in with a one-time code
3304
+ ```
3305
+
3254
3306
  ## Theming
3255
3307
 
3256
3308
  ```tsx
@@ -39,6 +39,7 @@ const ROUTES: RouteDefinition[] = [
39
39
  { name: "change_password", path: "api/hazo_auth/change_password", method: "POST", export_name: "changePasswordPOST" },
40
40
  { name: "upload_profile_picture", path: "api/hazo_auth/upload_profile_picture", method: "POST", export_name: "uploadProfilePicturePOST" },
41
41
  { name: "remove_profile_picture", path: "api/hazo_auth/remove_profile_picture", method: "DELETE", export_name: "removeProfilePictureDELETE" },
42
+ { name: "delete_account", path: "api/hazo_auth/delete_account", method: "DELETE", export_name: "deleteAccountDELETE" },
42
43
  { name: "library_photos", path: "api/hazo_auth/library_photos", method: "GET", export_name: "libraryPhotosGET" },
43
44
  { name: "library_photo", path: "api/hazo_auth/library_photo/[category]/[filename]", method: "GET", export_name: "libraryPhotoGET" },
44
45
  { name: "get_auth", path: "api/hazo_auth/get_auth", method: "POST", export_name: "getAuthPOST" },
@@ -32,9 +32,18 @@ import {
32
32
  const DEFAULT_SCOPE_HEADER = "X-Hazo-Scope-Id";
33
33
 
34
34
  /**
35
- * Base cookie name for scope ID (will have prefix applied)
35
+ * Base cookie name for scope ID (will have prefix applied).
36
+ *
37
+ * Exported so a consuming app can SET the same cookie this module READS —
38
+ * without it, an app implementing a scope switcher has to duplicate the
39
+ * configured prefix and drift the moment it changes.
36
40
  */
37
- const BASE_SCOPE_COOKIE = "hazo_auth_scope_id";
41
+ export const SCOPE_COOKIE_BASE_NAME = "hazo_auth_scope_id";
42
+
43
+ /** The live, prefixed scope cookie name for this deployment. */
44
+ export function get_scope_cookie_name(): string {
45
+ return get_cookie_name(SCOPE_COOKIE_BASE_NAME);
46
+ }
38
47
 
39
48
  // section: helpers
40
49
 
@@ -57,7 +66,7 @@ export function extract_scope_id_from_request(
57
66
  }
58
67
 
59
68
  // Check cookie (with prefix)
60
- const cookie_name = options.scope_cookie_name || get_cookie_name(BASE_SCOPE_COOKIE);
69
+ const cookie_name = options.scope_cookie_name || get_cookie_name(SCOPE_COOKIE_BASE_NAME);
61
70
  const cookie_value = request.cookies.get(cookie_name)?.value;
62
71
  return cookie_value;
63
72
  }
@@ -19,6 +19,8 @@ export {
19
19
  hazo_get_tenant_auth,
20
20
  require_tenant_auth,
21
21
  extract_scope_id_from_request,
22
+ SCOPE_COOKIE_BASE_NAME,
23
+ get_scope_cookie_name,
22
24
  } from "./hazo_get_tenant_auth.server.js";
23
25
  export type {
24
26
  ScopeDetails,
@@ -2,6 +2,7 @@
2
2
  // section: server-only-guard
3
3
  import "server-only";
4
4
 
5
+ import type { NextResponse } from "next/server";
5
6
  import { HazoConfigError } from "hazo_core";
6
7
  import { read_config_section } from "./config/config_loader.server.js";
7
8
 
@@ -109,3 +110,52 @@ export function get_cached_cookies_config(): CookiesConfig {
109
110
  export function clear_cookies_config_cache(): void {
110
111
  cached_config = null;
111
112
  }
113
+
114
+ /**
115
+ * Clears the three core hazo_auth session cookies (USER_EMAIL, USER_ID, SESSION)
116
+ * from a response, honoring the configured cookie prefix/domain. This is the same
117
+ * clearing logic used by the logout route; reuse it anywhere a session needs to be
118
+ * torn down (e.g. self-service account deletion) instead of re-implementing it.
119
+ * @param response - NextResponse object to clear cookies from
120
+ * @returns The same response, with cleared cookies (for chaining)
121
+ */
122
+ export function clear_session_cookies<T extends NextResponse>(response: T): T {
123
+ const clear_cookie_options = get_cookie_options({
124
+ expires: new Date(0),
125
+ path: "/",
126
+ });
127
+
128
+ response.cookies.set(get_cookie_name(BASE_COOKIE_NAMES.USER_EMAIL), "", clear_cookie_options);
129
+ response.cookies.set(get_cookie_name(BASE_COOKIE_NAMES.USER_ID), "", clear_cookie_options);
130
+ response.cookies.set(get_cookie_name(BASE_COOKIE_NAMES.SESSION), "", clear_cookie_options);
131
+
132
+ return response;
133
+ }
134
+
135
+ /**
136
+ * Clears the NextAuth.js cookies used by the Google OAuth flow (session token,
137
+ * CSRF token, callback URL — plus their `__Secure-`/`__Host-` production variants)
138
+ * from a response. This is the same clearing logic used by the logout route; reuse
139
+ * it anywhere a NextAuth-backed session needs to be torn down (e.g. self-service
140
+ * account deletion) instead of re-implementing it.
141
+ * @param response - NextResponse object to clear cookies from
142
+ * @returns The same response, with cleared cookies (for chaining)
143
+ */
144
+ export function clear_nextauth_cookies<T extends NextResponse>(response: T): T {
145
+ const clear_cookie_options = {
146
+ expires: new Date(0),
147
+ path: "/",
148
+ };
149
+
150
+ response.cookies.set("next-auth.session-token", "", clear_cookie_options);
151
+ response.cookies.set("next-auth.csrf-token", "", clear_cookie_options);
152
+ response.cookies.set("next-auth.callback-url", "", clear_cookie_options);
153
+ // Also clear secure cookie variants (used in production with HTTPS)
154
+ response.cookies.set("__Secure-next-auth.session-token", "", clear_cookie_options);
155
+ response.cookies.set("__Secure-next-auth.csrf-token", "", clear_cookie_options);
156
+ response.cookies.set("__Secure-next-auth.callback-url", "", clear_cookie_options);
157
+ // Host-prefixed variants (for some NextAuth configurations)
158
+ response.cookies.set("__Host-next-auth.csrf-token", "", clear_cookie_options);
159
+
160
+ return response;
161
+ }
@@ -3,7 +3,7 @@
3
3
  import "server-only";
4
4
 
5
5
  // section: imports
6
- import { get_config_value } from "./config/config_loader.server.js";
6
+ import { get_config_value, get_config_boolean } from "./config/config_loader.server.js";
7
7
  import { get_user_fields_config } from "./user_fields_config.server.js";
8
8
  import { get_password_requirements_config } from "./password_requirements_config.server.js";
9
9
  import { get_profile_picture_config } from "./profile_picture_config.server.js";
@@ -49,6 +49,8 @@ export type MySettingsConfig = {
49
49
  unauthorizedMessage?: string;
50
50
  loginButtonLabel?: string;
51
51
  loginPath?: string;
52
+ /** Opt-in self-service account deletion (Danger Zone). Default: false. */
53
+ enableAccountDeletion: boolean;
52
54
  messages: {
53
55
  photo_upload_disabled_message: string;
54
56
  gravatar_setup_message: string;
@@ -110,6 +112,7 @@ export function get_my_settings_config(): MySettingsConfig {
110
112
  const unauthorizedMessage = get_config_value(section, "unauthorized_message", "You must be logged in to access this page.");
111
113
  const loginButtonLabel = get_config_value(section, "login_button_label", "Go to login");
112
114
  const loginPath = get_config_value(section, "login_path", "/hazo_auth/login");
115
+ const enableAccountDeletion = get_config_boolean(section, "enable_account_deletion", false);
113
116
 
114
117
  return {
115
118
  userFields,
@@ -130,6 +133,7 @@ export function get_my_settings_config(): MySettingsConfig {
130
133
  unauthorizedMessage,
131
134
  loginButtonLabel,
132
135
  loginPath,
136
+ enableAccountDeletion,
133
137
  messages,
134
138
  uiSizes,
135
139
  fileTypes,
@@ -18,6 +18,11 @@ export const OTP_CONFIG_DEFAULTS = {
18
18
  max_verify_attempts: 5,
19
19
  auto_assign_scope_id: "00000000-0000-0000-0000-000000000001",
20
20
  auto_assign_role_name: "member",
21
+ // Matches OTPLayout's own default. Apps that never ran `npx hazo_auth init`
22
+ // (so have no public/hazo_auth/images/) should point this at the packaged
23
+ // asset route instead: /api/hazo_auth/assets/login_default.jpg
24
+ image_src: "/hazo_auth/images/login_default.jpg",
25
+ image_alt: "Sign in with a one-time code",
21
26
  } as const;
22
27
 
23
28
  // section: types
@@ -44,6 +49,10 @@ export type OtpConfig = {
44
49
  auto_assign_scope_id: string;
45
50
  /** Role name to assign within the auto-assign scope */
46
51
  auto_assign_role_name: string;
52
+ /** Image shown in the OTP page's visual panel */
53
+ image_src: string;
54
+ /** Alt text for the OTP page's visual panel image */
55
+ image_alt: string;
47
56
  };
48
57
 
49
58
  // section: helpers
@@ -79,6 +88,8 @@ export function get_otp_config(): OtpConfig {
79
88
  max_verify_attempts: get_config_number(section, "otp_max_verify_attempts", d.max_verify_attempts),
80
89
  auto_assign_scope_id: get_config_value(section, "otp_auto_assign_scope_id", d.auto_assign_scope_id),
81
90
  auto_assign_role_name: get_config_value(section, "otp_auto_assign_role_name", d.auto_assign_role_name),
91
+ image_src: get_config_value(section, "otp_image_src", d.image_src),
92
+ image_alt: get_config_value(section, "otp_image_alt", d.image_alt),
82
93
  };
83
94
  }
84
95
 
@@ -0,0 +1,67 @@
1
+ // file_description: service for self-service (hard) deletion of the caller's own hazo_users row
2
+ // section: imports
3
+ import { createCrudService } from "hazo_connect/server";
4
+ import { get_hazo_connect_instance } from "../hazo_connect_instance.server.js";
5
+ import { create_app_logger } from "../app_logger.js";
6
+ import { sanitize_error_for_user } from "../utils/error_sanitizer.js";
7
+ import { get_line_number } from "../utils/api_route_helpers.js";
8
+
9
+ // section: types
10
+ export type AccountDeletionResult = {
11
+ success: boolean;
12
+ error?: string;
13
+ };
14
+
15
+ // section: main_function
16
+ /**
17
+ * Hard-deletes the caller's own `hazo_users` row.
18
+ *
19
+ * Child rows cascade automatically via `ON DELETE CASCADE` foreign keys
20
+ * (hazo_refresh_tokens, hazo_user_scopes, hazo_user_relationships,
21
+ * hazo_email_otps, hazo_legal_acceptances, hazo_google_oauth_tokens,
22
+ * hazo_user_roles) — no manual cleanup needed. A few "created by" /
23
+ * "managed by" references (hazo_users.managed_by_user_id,
24
+ * hazo_invitations.invited_by, hazo_legal_doc_versions.published_by_user_id)
25
+ * intentionally use `ON DELETE SET NULL` instead of CASCADE, by design —
26
+ * they preserve audit/history/relationship rows rather than deleting them,
27
+ * so they likewise require no manual cleanup here.
28
+ *
29
+ * @param user_id - The authenticated caller's own user ID (never another user's)
30
+ * @returns AccountDeletionResult with success status or error
31
+ */
32
+ export async function delete_own_account(
33
+ user_id: string,
34
+ ): Promise<AccountDeletionResult> {
35
+ try {
36
+ const adapter = get_hazo_connect_instance();
37
+ const users_service = createCrudService(adapter, "hazo_users");
38
+
39
+ // Verify the user still exists before deleting
40
+ const users = await users_service.findBy({ id: user_id });
41
+ if (!Array.isArray(users) || users.length === 0) {
42
+ return { success: false, error: "User not found" };
43
+ }
44
+
45
+ await users_service.deleteById(user_id);
46
+
47
+ return { success: true };
48
+ } catch (error) {
49
+ const logger = create_app_logger();
50
+ const user_friendly_error = sanitize_error_for_user(error, {
51
+ logToConsole: true,
52
+ logToLogger: true,
53
+ logger,
54
+ context: {
55
+ filename: "account_deletion_service.ts",
56
+ line_number: get_line_number(),
57
+ user_id,
58
+ operation: "delete_own_account",
59
+ },
60
+ });
61
+
62
+ return {
63
+ success: false,
64
+ error: user_friendly_error,
65
+ };
66
+ }
67
+ }
@@ -22,4 +22,5 @@ export * from "./oauth_service.js";
22
22
  export * from "./branding_service.js";
23
23
  export * from "./google_token_service.js";
24
24
  export * from "./demo_account_service.js";
25
+ export * from "./account_deletion_service.js";
25
26
 
@@ -23,6 +23,25 @@ cookie_prefix = myapp_
23
23
  # Database type: sqlite, postgrest, supabase, or file
24
24
  type = sqlite
25
25
 
26
+ # SQLite database configuration
27
+ # Path to SQLite database file (relative to process.cwd() or absolute)
28
+ sqlite_path = ./data/hazo_auth.sqlite
29
+
30
+ # Enable SQLite admin UI (true/false)
31
+ enable_admin_ui = true
32
+
33
+ # SQLite read-only mode (true/false)
34
+ # read_only = false
35
+
36
+ # PostgREST configuration (uncomment if using postgrest type)
37
+ # postgrest_url =
38
+
39
+ # PostgREST API Key (REQUIRED if PostgREST uses authentication)
40
+ # IMPORTANT: API keys should ONLY be set in environment variables for security
41
+ # Set HAZO_CONNECT_POSTGREST_API_KEY or POSTGREST_API_KEY in your .env file
42
+ # DO NOT put API keys in this config file
43
+ # postgrest_api_key =
44
+
26
45
  # UI shell controls whether pages render inside the developer sidebar or a minimal wrapper.
27
46
  [hazo_auth__ui_shell]
28
47
  # layout_mode = test_sidebar
@@ -48,25 +67,6 @@ type = sqlite
48
67
  # Show/hide description in standalone mode (true/false, default: true)
49
68
  # standalone_show_description = true
50
69
 
51
- # SQLite database configuration
52
- # Path to SQLite database file (relative to process.cwd() or absolute)
53
- sqlite_path = ./data/hazo_auth.sqlite
54
-
55
- # Enable SQLite admin UI (true/false)
56
- enable_admin_ui = true
57
-
58
- # SQLite read-only mode (true/false)
59
- # read_only = false
60
-
61
- # PostgREST configuration (uncomment if using postgrest type)
62
- # postgrest_url =
63
-
64
- # PostgREST API Key (REQUIRED if PostgREST uses authentication)
65
- # IMPORTANT: API keys should ONLY be set in environment variables for security
66
- # Set HAZO_CONNECT_POSTGREST_API_KEY or POSTGREST_API_KEY in your .env file
67
- # DO NOT put API keys in this config file
68
- # postgrest_api_key =
69
-
70
70
  [hazo_auth__register_layout]
71
71
  # Image configuration
72
72
  # Default: /hazo_auth/images/register_default.jpg (copy from node_modules/hazo_auth/public/hazo_auth)
@@ -123,6 +123,14 @@ enable_admin_ui = true
123
123
  # require_number = false
124
124
  # require_special = false
125
125
 
126
+ [hazo_auth__otp]
127
+ # Visual panel image on the email-OTP sign-in page.
128
+ # Default: /hazo_auth/images/login_default.jpg — i.e. the copy `npx hazo_auth init`
129
+ # places in your public/ directory. Apps that skipped that copy should point this
130
+ # at the packaged asset route instead:
131
+ # otp_image_src = /api/hazo_auth/assets/login_default.jpg
132
+ # otp_image_alt = Sign in with a one-time code
133
+
126
134
  [hazo_auth__login_layout]
127
135
  # Image configuration
128
136
  # image_src = /globe.svg
@@ -308,6 +316,12 @@ enable_admin_ui = true
308
316
  # Login path (redirect target in unauthorized message)
309
317
  # login_path = /login
310
318
 
319
+ # Self-service account deletion (Danger Zone). Opt-in — off by default.
320
+ # When true, an authenticated user may hard-delete their own account via
321
+ # DELETE /api/hazo_auth/delete_account (re-typing their own email as confirmation).
322
+ # The hazo_users row and all cascading child rows (sessions, scopes, etc.) are removed.
323
+ # enable_account_deletion = false
324
+
311
325
  [hazo_auth__user_management]
312
326
  # User Management configuration
313
327
  # Application permission list defaults (comma-separated)
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/cli/generate.ts"],"names":[],"mappings":"AAqBA,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAuMF,wBAAgB,eAAe,CAAC,OAAO,GAAE,eAAoB,GAAG,IAAI,CA8DnE"}
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/cli/generate.ts"],"names":[],"mappings":"AAqBA,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAwMF,wBAAgB,eAAe,CAAC,OAAO,GAAE,eAAoB,GAAG,IAAI,CA8DnE"}
@@ -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" },
@@ -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,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,UAAU,EAAE;QACV,eAAe,EAAE,OAAO,CAAC;QACzB,gBAAgB,EAAE,OAAO,CAAC;QAC1B,mBAAmB,EAAE,OAAO,CAAC;KAC9B,CAAC;IACF,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,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,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;;;;;;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,SAAS,CAAC;QACrD,4BAA4B,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;QACtD,kBAAkB,EAAE,MAAM,CAAC;KAC5B,CAAC;IACF,UAAU,EAAE;QACV,eAAe,EAAE,OAAO,CAAC;QACzB,gBAAgB,EAAE,OAAO,CAAC;QAC1B,mBAAmB,EAAE,OAAO,CAAC;KAC9B,CAAC;IACF,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,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,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;;;;;;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,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> {