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
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.
@@ -2170,6 +2170,55 @@ curl -H "Cookie: hazo_auth_session=YOUR_TOKEN; hazo_auth_scope_id=SCOPE_UUID" \
2170
2170
 
2171
2171
  ---
2172
2172
 
2173
+ ## Phase 8.1: Permission-Denied UX Setup (Optional)
2174
+
2175
+ `withAuth` (and `withPermissionIssueCapture`) return the canonical `hazo_api`
2176
+ `FORBIDDEN` envelope on every permission denial and best-effort escalate to a
2177
+ registered handler. Wiring the client + server surfaces is **one call each**:
2178
+
2179
+ **Client-side (once, at the app root):**
2180
+ ```typescript
2181
+ import { PermissionFailureProvider } from "hazo_auth/client";
2182
+ import { HazoUiToaster } from "hazo_ui";
2183
+
2184
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
2185
+ return (
2186
+ <html lang="en">
2187
+ <body>
2188
+ <PermissionFailureProvider>{children}</PermissionFailureProvider>
2189
+ <HazoUiToaster />
2190
+ </body>
2191
+ </html>
2192
+ );
2193
+ }
2194
+ ```
2195
+ Mount `<PermissionFailureProvider>` + `<HazoUiToaster>` once client-side — every
2196
+ 403 fetched via `fetchWithPermissionCapture` (or manually passed to
2197
+ `handlePermissionDenied`) now surfaces a toast. Prefer the heavier
2198
+ `<PermissionDeniedProvider>` (a modal dialog) instead if you want a blocking
2199
+ surface — the two are mutually exclusive; whichever is mounted wins.
2200
+
2201
+ **Server-side (once, at boot):**
2202
+ ```typescript
2203
+ import { installPermissionUX } from "hazo_auth/server-lib";
2204
+
2205
+ installPermissionUX({
2206
+ getAdapter: () => get_hazo_connect_instance(),
2207
+ createIssueStore: (adapter) => createIssueStore(adapter),
2208
+ registerType: (def) => issueRegistry.register(def),
2209
+ });
2210
+ ```
2211
+ `installPermissionUX(...)` registers the `auth_permission` issue type and wires
2212
+ the escalation handler so every FORBIDDEN denial best-effort bumps/creates an
2213
+ admin issue — same options as `wireAdminIssueCapture` (which it wraps).
2214
+
2215
+ **Permission-Denied UX Checklist:**
2216
+ - [ ] `<PermissionFailureProvider>` (toast) or `<PermissionDeniedProvider>` (dialog) mounted once at the client root
2217
+ - [ ] `<HazoUiToaster>` mounted once (only needed for the toast surface)
2218
+ - [ ] `installPermissionUX(...)` called once at server boot
2219
+
2220
+ ---
2221
+
2173
2222
  ## Troubleshooting
2174
2223
 
2175
2224
  ### Issue: "User is inactive" or "auth_utility_fetch_user_failed" errors
@@ -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" },
@@ -15,6 +15,13 @@ import {
15
15
  type ScopeDetails,
16
16
  type ScopeAccessInfo,
17
17
  } from "./auth_types.js";
18
+ import {
19
+ buildForbiddenResponse,
20
+ buildDenialPayloadFromRequest,
21
+ getPermissionDeniedHandler,
22
+ type PermissionDeniedPayload,
23
+ } from "./with_permission_issue_capture.server.js";
24
+ import { get_app_permission_descriptions } from "../app_permissions_config.server.js";
18
25
 
19
26
  // section: types
20
27
 
@@ -90,10 +97,43 @@ type OptionalAuthHandler<TParams> = (
90
97
 
91
98
  // section: error_response_helper
92
99
 
100
+ /** Converts get_app_permission_descriptions()'s Map into the Record shape PermissionDeniedPayload expects. */
101
+ function descriptions_map_to_record(
102
+ map: Map<string, string>,
103
+ ): Record<string, string> {
104
+ return Object.fromEntries(map);
105
+ }
106
+
107
+ /**
108
+ * Fire the denial escalation handler best-effort (never awaited, never
109
+ * throws), then return the canonical FORBIDDEN envelope.
110
+ */
111
+ async function respond_permission_denied(
112
+ payload: PermissionDeniedPayload,
113
+ ): Promise<NextResponse> {
114
+ try {
115
+ const handler = getPermissionDeniedHandler();
116
+ if (handler) {
117
+ // fire-and-forget; escalation must never delay or fail the 403
118
+ Promise.resolve()
119
+ .then(() => handler(payload))
120
+ .catch(() => {
121
+ /* swallow */
122
+ });
123
+ }
124
+ } catch {
125
+ /* swallow */
126
+ }
127
+ return (await buildForbiddenResponse(payload)) as unknown as NextResponse;
128
+ }
129
+
93
130
  /**
94
131
  * Converts caught errors into appropriate NextResponse JSON responses
95
132
  */
96
- function handle_auth_error(error: unknown): NextResponse {
133
+ async function handle_auth_error(
134
+ error: unknown,
135
+ request: Request,
136
+ ): Promise<NextResponse> {
97
137
  if (error instanceof HazoAuthError) {
98
138
  return NextResponse.json(
99
139
  { error: error.message, code: error.code },
@@ -102,14 +142,18 @@ function handle_auth_error(error: unknown): NextResponse {
102
142
  }
103
143
 
104
144
  if (error instanceof PermissionError) {
105
- return NextResponse.json(
106
- {
107
- error: error.message,
108
- code: "PERMISSION_DENIED",
109
- missing_permissions: error.missing_permissions,
110
- },
111
- { status: 403 },
145
+ const descriptions = get_app_permission_descriptions(
146
+ error.missing_permissions ?? [],
112
147
  );
148
+ const payload = buildDenialPayloadFromRequest(request, {
149
+ user_id: "",
150
+ missing_permissions: error.missing_permissions ?? [],
151
+ required_permissions:
152
+ error.required_permissions ?? error.missing_permissions ?? [],
153
+ permission_descriptions: descriptions_map_to_record(descriptions),
154
+ user_permissions: error.user_permissions ?? [],
155
+ });
156
+ return respond_permission_denied(payload);
113
157
  }
114
158
 
115
159
  console.error("Unexpected error in route handler:", error);
@@ -210,20 +254,18 @@ export function withAuth<TParams = Record<string, never>>(
210
254
 
211
255
  // Check permissions if required_permissions were specified
212
256
  if (options.required_permissions?.length && !auth.permission_ok) {
213
- return NextResponse.json(
214
- {
215
- error: "Insufficient permissions",
216
- code: "PERMISSION_DENIED",
217
- missing_permissions: auth.missing_permissions,
218
- ...(process.env.NODE_ENV === "development" && {
219
- debug: {
220
- user_permissions: auth.permissions,
221
- required_permissions: options.required_permissions,
222
- },
223
- }),
224
- },
225
- { status: 403 },
257
+ const descriptions = get_app_permission_descriptions(
258
+ auth.missing_permissions ?? [],
226
259
  );
260
+ const payload = buildDenialPayloadFromRequest(request, {
261
+ user_id: auth.user?.id ?? "",
262
+ scope_id: options.scope_id,
263
+ missing_permissions: auth.missing_permissions ?? [],
264
+ required_permissions: options.required_permissions,
265
+ permission_descriptions: descriptions_map_to_record(descriptions),
266
+ user_permissions: auth.permissions,
267
+ });
268
+ return respond_permission_denied(payload);
227
269
  }
228
270
 
229
271
  // Check tenant requirement
@@ -246,7 +288,7 @@ export function withAuth<TParams = Record<string, never>>(
246
288
  params,
247
289
  );
248
290
  } catch (error) {
249
- return handle_auth_error(error);
291
+ return await handle_auth_error(error, request);
250
292
  }
251
293
  };
252
294
  }
@@ -285,7 +327,7 @@ export function withOptionalAuth<TParams = Record<string, never>>(
285
327
  const params = await resolve_params(context);
286
328
  return await handler(request, auth, params);
287
329
  } catch (error) {
288
- return handle_auth_error(error);
330
+ return await handle_auth_error(error, request);
289
331
  }
290
332
  };
291
333
  }
@@ -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,
@@ -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)
@@ -308,6 +308,12 @@ enable_admin_ui = true
308
308
  # Login path (redirect target in unauthorized message)
309
309
  # login_path = /login
310
310
 
311
+ # Self-service account deletion (Danger Zone). Opt-in — off by default.
312
+ # When true, an authenticated user may hard-delete their own account via
313
+ # DELETE /api/hazo_auth/delete_account (re-typing their own email as confirmation).
314
+ # The hazo_users row and all cascading child rows (sessions, scopes, etc.) are removed.
315
+ # enable_account_deletion = false
316
+
311
317
  [hazo_auth__user_management]
312
318
  # User Management configuration
313
319
  # Application permission list defaults (comma-separated)
@@ -0,0 +1,26 @@
1
+ import 'server-only';
2
+ import { type WireAdminIssueCaptureOptions } from './wire.server.js';
3
+ export type InstallPermissionUXOptions = WireAdminIssueCaptureOptions;
4
+ /**
5
+ * Mounts the server side of the permission-UX stack in one call, at app boot.
6
+ *
7
+ * Forwards straight to `wireAdminIssueCapture`, which:
8
+ * 1. registers the `auth_permission` issue type with hazo_admin, and
9
+ * 2. calls `setPermissionDeniedHandler(...)` so every FORBIDDEN denial from
10
+ * `withAuth` / `withPermissionIssueCapture` best-effort escalates to the
11
+ * admin issue store.
12
+ *
13
+ * `installPermissionUX` exists as the documented, memorable name for that
14
+ * boot-time call — pair it client-side with `<PermissionFailureProvider>` (or
15
+ * `<PermissionDeniedProvider>`) + `<HazoUiToaster>` mounted once.
16
+ *
17
+ * Usage:
18
+ * // instrumentation.ts / app bootstrap
19
+ * installPermissionUX({
20
+ * getAdapter: () => get_hazo_connect_instance(),
21
+ * createIssueStore: (adapter) => createIssueStore(adapter),
22
+ * registerType: (def) => issueRegistry.register(def),
23
+ * });
24
+ */
25
+ export declare function installPermissionUX(opts: InstallPermissionUXOptions): void;
26
+ //# sourceMappingURL=install_permission_ux.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install_permission_ux.server.d.ts","sourceRoot":"","sources":["../../src/admin-issues/install_permission_ux.server.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAyB,KAAK,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAEzF,MAAM,MAAM,0BAA0B,GAAG,4BAA4B,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,0BAA0B,GAAG,IAAI,CAE1E"}
@@ -0,0 +1,27 @@
1
+ // file_description: single documented entrypoint that wires the whole permission-UX stack server-side
2
+ import 'server-only';
3
+ import { wireAdminIssueCapture } from './wire.server.js';
4
+ /**
5
+ * Mounts the server side of the permission-UX stack in one call, at app boot.
6
+ *
7
+ * Forwards straight to `wireAdminIssueCapture`, which:
8
+ * 1. registers the `auth_permission` issue type with hazo_admin, and
9
+ * 2. calls `setPermissionDeniedHandler(...)` so every FORBIDDEN denial from
10
+ * `withAuth` / `withPermissionIssueCapture` best-effort escalates to the
11
+ * admin issue store.
12
+ *
13
+ * `installPermissionUX` exists as the documented, memorable name for that
14
+ * boot-time call — pair it client-side with `<PermissionFailureProvider>` (or
15
+ * `<PermissionDeniedProvider>`) + `<HazoUiToaster>` mounted once.
16
+ *
17
+ * Usage:
18
+ * // instrumentation.ts / app bootstrap
19
+ * installPermissionUX({
20
+ * getAdapter: () => get_hazo_connect_instance(),
21
+ * createIssueStore: (adapter) => createIssueStore(adapter),
22
+ * registerType: (def) => issueRegistry.register(def),
23
+ * });
24
+ */
25
+ export function installPermissionUX(opts) {
26
+ wireAdminIssueCapture(opts);
27
+ }
@@ -1,12 +1,31 @@
1
1
  import React from 'react';
2
2
  import { type PermissionDeniedDetails } from '../components/permission_denied_dialog.client.js';
3
3
  export declare function showPermissionDeniedDialog(details: PermissionDeniedDetails, message?: string): void;
4
+ export type PermissionFailureSurface = (details: PermissionDeniedDetails, message?: string) => void | Promise<void>;
5
+ /**
6
+ * Registers the active permission-failure surface. The most recently mounted
7
+ * provider wins; pass `null` to clear (done automatically on unmount by the
8
+ * providers below). Exported for `PermissionFailureProvider` and for tests —
9
+ * consuming apps normally just mount a provider instead of calling this.
10
+ */
11
+ export declare function registerPermissionFailureSurface(surface: PermissionFailureSurface | null): void;
4
12
  export interface PermissionDeniedProviderProps {
5
13
  children?: React.ReactNode;
6
14
  registerCardRenderer?: (typeKey: string, renderer: React.ComponentType<any>) => void;
7
15
  }
8
16
  export declare function PermissionDeniedProvider({ children, registerCardRenderer }: PermissionDeniedProviderProps): React.JSX.Element;
9
17
  export declare function handlePermissionDenied(response: Response): Promise<boolean>;
18
+ export interface PermissionFailureProviderProps {
19
+ children?: React.ReactNode;
20
+ registerCardRenderer?: (typeKey: string, renderer: React.ComponentType<any>) => void;
21
+ }
22
+ /**
23
+ * Batteries-included permission-failure surface: renders a toast via hazo_ui's
24
+ * `permissionToast` (dynamically imported so hazo_ui stays an optional peer).
25
+ * Unlike `PermissionDeniedProvider`, this renders no dialog itself — mount
26
+ * `<HazoUiToaster>` once alongside it for the toast to actually appear.
27
+ */
28
+ export declare function PermissionFailureProvider({ children, registerCardRenderer }: PermissionFailureProviderProps): React.JSX.Element;
10
29
  export declare function fetchWithPermissionCapture(input: RequestInfo | URL, init?: RequestInit & {
11
30
  originUrl?: string;
12
31
  actionLabel?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"permission_denied_provider.client.d.ts","sourceRoot":"","sources":["../../src/admin-issues/permission_denied_provider.client.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,+CAA+C,CAAC;AAOvD,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,uBAAuB,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAInG;AAID,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;CACtF;AAED,wBAAgB,wBAAwB,CAAC,EAAE,QAAQ,EAAE,oBAAoB,EAAE,EAAE,6BAA6B,qBAgCzG;AAID,wBAAsB,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CAmBjF;AAID,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAChE,OAAO,CAAC,QAAQ,CAAC,CAcnB"}
1
+ {"version":3,"file":"permission_denied_provider.client.d.ts","sourceRoot":"","sources":["../../src/admin-issues/permission_denied_provider.client.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,+CAA+C,CAAC;AAOvD,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,uBAAuB,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAInG;AASD,MAAM,MAAM,wBAAwB,GAAG,CACrC,OAAO,EAAE,uBAAuB,EAChC,OAAO,CAAC,EAAE,MAAM,KACb,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAI1B;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI,GAAG,IAAI,CAE/F;AAID,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;CACtF;AAED,wBAAgB,wBAAwB,CAAC,EAAE,QAAQ,EAAE,oBAAoB,EAAE,EAAE,6BAA6B,qBAgCzG;AAID,wBAAsB,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CA0BjF;AAID,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;CACtF;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,EAAE,QAAQ,EAAE,oBAAoB,EAAE,EAAE,8BAA8B,qBAuB3G;AAID,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAChE,OAAO,CAAC,QAAQ,CAAC,CAcnB"}
@@ -22,6 +22,16 @@ export function showPermissionDeniedDialog(details, message) {
22
22
  _showDialog(details, message);
23
23
  }
24
24
  }
25
+ let _surface = null;
26
+ /**
27
+ * Registers the active permission-failure surface. The most recently mounted
28
+ * provider wins; pass `null` to clear (done automatically on unmount by the
29
+ * providers below). Exported for `PermissionFailureProvider` and for tests —
30
+ * consuming apps normally just mount a provider instead of calling this.
31
+ */
32
+ export function registerPermissionFailureSurface(surface) {
33
+ _surface = surface;
34
+ }
25
35
  export function PermissionDeniedProvider({ children, registerCardRenderer }) {
26
36
  const [open, setOpen] = useState(false);
27
37
  const [details, setDetails] = useState(null);
@@ -47,7 +57,10 @@ export async function handlePermissionDenied(response) {
47
57
  try {
48
58
  const cloned = response.clone();
49
59
  const body = await cloned.json();
50
- if (((_a = body === null || body === void 0 ? void 0 : body.error) === null || _a === void 0 ? void 0 : _a.code) !== 'FORBIDDEN')
60
+ // 'FORBIDDEN' is the canonical code emitted by withAuth/withPermissionIssueCapture.
61
+ // 'PERMISSION_DENIED' is accepted for back-compat with pre-FR-017 servers.
62
+ const code = (_a = body === null || body === void 0 ? void 0 : body.error) === null || _a === void 0 ? void 0 : _a.code;
63
+ if (code !== 'FORBIDDEN' && code !== 'PERMISSION_DENIED')
51
64
  return false;
52
65
  const errDetails = (_b = body.error.details) !== null && _b !== void 0 ? _b : {};
53
66
  const permDetails = {
@@ -56,13 +69,44 @@ export async function handlePermissionDenied(response) {
56
69
  action_label: errDetails.action_label,
57
70
  origin_url: errDetails.origin_url,
58
71
  };
59
- showPermissionDeniedDialog(permDetails, body.error.message);
72
+ if (_surface) {
73
+ _surface(permDetails, body.error.message);
74
+ }
75
+ else {
76
+ showPermissionDeniedDialog(permDetails, body.error.message);
77
+ }
60
78
  return true;
61
79
  }
62
80
  catch (_c) {
63
81
  return false;
64
82
  }
65
83
  }
84
+ /**
85
+ * Batteries-included permission-failure surface: renders a toast via hazo_ui's
86
+ * `permissionToast` (dynamically imported so hazo_ui stays an optional peer).
87
+ * Unlike `PermissionDeniedProvider`, this renders no dialog itself — mount
88
+ * `<HazoUiToaster>` once alongside it for the toast to actually appear.
89
+ */
90
+ export function PermissionFailureProvider({ children, registerCardRenderer }) {
91
+ useEffect(() => {
92
+ _surface = async (details, message) => {
93
+ var _a, _b;
94
+ const ui = (await import('hazo_ui').catch(() => null));
95
+ (_a = ui === null || ui === void 0 ? void 0 : ui.permissionToast) === null || _a === void 0 ? void 0 : _a.call(ui, {
96
+ missingPermissions: (_b = details.missing_permissions) !== null && _b !== void 0 ? _b : [],
97
+ descriptions: details.permission_descriptions,
98
+ });
99
+ void message; // toast has no separate title/message slot beyond permissionToast's own copy
100
+ };
101
+ if (registerCardRenderer) {
102
+ registerCardRenderer('auth_permission', AuthIssueCard);
103
+ }
104
+ return () => {
105
+ _surface = null;
106
+ };
107
+ }, [registerCardRenderer]);
108
+ return _jsx(_Fragment, { children: children });
109
+ }
66
110
  // ── fetchWithPermissionCapture ────────────────────────────────────────────────
67
111
  export async function fetchWithPermissionCapture(input, init) {
68
112
  var _a;
@@ -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"}