hazo_auth 4.1.0 → 4.3.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 (157) hide show
  1. package/README.md +230 -0
  2. package/SETUP_CHECKLIST.md +202 -0
  3. package/bin/hazo_auth.mjs +35 -0
  4. package/cli-src/assets/images/forgot_password_default.jpg +0 -0
  5. package/cli-src/assets/images/login_default.jpg +0 -0
  6. package/cli-src/assets/images/register_default.jpg +0 -0
  7. package/cli-src/assets/images/reset_password_default.jpg +0 -0
  8. package/cli-src/assets/images/verify_email_default.jpg +0 -0
  9. package/cli-src/cli/generate.ts +276 -0
  10. package/cli-src/cli/index.ts +207 -0
  11. package/cli-src/cli/init.ts +254 -0
  12. package/cli-src/cli/init_users.ts +376 -0
  13. package/cli-src/cli/validate.ts +581 -0
  14. package/cli-src/lib/already_logged_in_config.server.ts +46 -0
  15. package/cli-src/lib/app_logger.ts +24 -0
  16. package/cli-src/lib/auth/auth_cache.ts +220 -0
  17. package/cli-src/lib/auth/auth_rate_limiter.ts +121 -0
  18. package/cli-src/lib/auth/auth_types.ts +110 -0
  19. package/cli-src/lib/auth/auth_utils.server.ts +196 -0
  20. package/cli-src/lib/auth/hazo_get_auth.server.ts +512 -0
  21. package/cli-src/lib/auth/index.ts +23 -0
  22. package/cli-src/lib/auth/nextauth_config.ts +227 -0
  23. package/cli-src/lib/auth/scope_cache.ts +233 -0
  24. package/cli-src/lib/auth/server_auth.ts +88 -0
  25. package/cli-src/lib/auth/session_token_validator.edge.ts +91 -0
  26. package/cli-src/lib/auth_utility_config.server.ts +136 -0
  27. package/cli-src/lib/config/config_loader.server.ts +164 -0
  28. package/cli-src/lib/config/default_config.ts +199 -0
  29. package/cli-src/lib/email_verification_config.server.ts +63 -0
  30. package/cli-src/lib/file_types_config.server.ts +25 -0
  31. package/cli-src/lib/forgot_password_config.server.ts +63 -0
  32. package/cli-src/lib/hazo_connect_instance.server.ts +101 -0
  33. package/cli-src/lib/hazo_connect_setup.server.ts +194 -0
  34. package/cli-src/lib/hazo_connect_setup.ts +54 -0
  35. package/cli-src/lib/index.ts +46 -0
  36. package/cli-src/lib/login_config.server.ts +106 -0
  37. package/cli-src/lib/messages_config.server.ts +45 -0
  38. package/cli-src/lib/migrations/apply_migration.ts +105 -0
  39. package/cli-src/lib/my_settings_config.server.ts +135 -0
  40. package/cli-src/lib/oauth_config.server.ts +87 -0
  41. package/cli-src/lib/password_requirements_config.server.ts +40 -0
  42. package/cli-src/lib/profile_pic_menu_config.server.ts +138 -0
  43. package/cli-src/lib/profile_picture_config.server.ts +56 -0
  44. package/cli-src/lib/register_config.server.ts +101 -0
  45. package/cli-src/lib/reset_password_config.server.ts +103 -0
  46. package/cli-src/lib/scope_hierarchy_config.server.ts +151 -0
  47. package/cli-src/lib/services/email_service.ts +587 -0
  48. package/cli-src/lib/services/email_verification_service.ts +270 -0
  49. package/cli-src/lib/services/index.ts +16 -0
  50. package/cli-src/lib/services/login_service.ts +150 -0
  51. package/cli-src/lib/services/oauth_service.ts +494 -0
  52. package/cli-src/lib/services/password_change_service.ts +154 -0
  53. package/cli-src/lib/services/password_reset_service.ts +418 -0
  54. package/cli-src/lib/services/profile_picture_remove_service.ts +120 -0
  55. package/cli-src/lib/services/profile_picture_service.ts +451 -0
  56. package/cli-src/lib/services/profile_picture_source_mapper.ts +62 -0
  57. package/cli-src/lib/services/registration_service.ts +185 -0
  58. package/cli-src/lib/services/scope_labels_service.ts +348 -0
  59. package/cli-src/lib/services/scope_service.ts +778 -0
  60. package/cli-src/lib/services/session_token_service.ts +177 -0
  61. package/cli-src/lib/services/token_service.ts +240 -0
  62. package/cli-src/lib/services/user_profiles_cache.ts +189 -0
  63. package/cli-src/lib/services/user_profiles_service.ts +264 -0
  64. package/cli-src/lib/services/user_scope_service.ts +554 -0
  65. package/cli-src/lib/services/user_update_service.ts +141 -0
  66. package/cli-src/lib/ui_shell_config.server.ts +73 -0
  67. package/cli-src/lib/ui_sizes_config.server.ts +37 -0
  68. package/cli-src/lib/user_fields_config.server.ts +31 -0
  69. package/cli-src/lib/user_management_config.server.ts +39 -0
  70. package/cli-src/lib/user_profiles_config.server.ts +55 -0
  71. package/cli-src/lib/utils/api_route_helpers.ts +60 -0
  72. package/cli-src/lib/utils/error_sanitizer.ts +75 -0
  73. package/cli-src/lib/utils/password_validator.ts +65 -0
  74. package/cli-src/lib/utils.ts +11 -0
  75. package/cli-src/server/logging/logger_service.ts +56 -0
  76. package/dist/app/api/hazo_auth/forgot_password/route.d.ts.map +1 -1
  77. package/dist/app/api/hazo_auth/forgot_password/route.js +15 -0
  78. package/dist/app/api/hazo_auth/logout/route.d.ts.map +1 -1
  79. package/dist/app/api/hazo_auth/logout/route.js +31 -0
  80. package/dist/app/api/hazo_auth/me/route.d.ts.map +1 -1
  81. package/dist/app/api/hazo_auth/me/route.js +10 -0
  82. package/dist/cli/index.js +18 -0
  83. package/dist/cli/init_users.d.ts +17 -0
  84. package/dist/cli/init_users.d.ts.map +1 -0
  85. package/dist/cli/init_users.js +307 -0
  86. package/dist/components/layouts/forgot_password/hooks/use_forgot_password_form.d.ts +2 -0
  87. package/dist/components/layouts/forgot_password/hooks/use_forgot_password_form.d.ts.map +1 -1
  88. package/dist/components/layouts/forgot_password/hooks/use_forgot_password_form.js +8 -0
  89. package/dist/components/layouts/forgot_password/index.d.ts +7 -1
  90. package/dist/components/layouts/forgot_password/index.d.ts.map +1 -1
  91. package/dist/components/layouts/forgot_password/index.js +7 -2
  92. package/dist/components/layouts/login/index.d.ts +13 -1
  93. package/dist/components/layouts/login/index.d.ts.map +1 -1
  94. package/dist/components/layouts/login/index.js +11 -2
  95. package/dist/components/layouts/my_settings/components/connected_accounts_section.d.ts +17 -0
  96. package/dist/components/layouts/my_settings/components/connected_accounts_section.d.ts.map +1 -0
  97. package/dist/components/layouts/my_settings/components/connected_accounts_section.js +17 -0
  98. package/dist/components/layouts/my_settings/components/set_password_section.d.ts +26 -0
  99. package/dist/components/layouts/my_settings/components/set_password_section.d.ts.map +1 -0
  100. package/dist/components/layouts/my_settings/components/set_password_section.js +127 -0
  101. package/dist/components/layouts/my_settings/hooks/use_my_settings.d.ts +3 -0
  102. package/dist/components/layouts/my_settings/hooks/use_my_settings.d.ts.map +1 -1
  103. package/dist/components/layouts/my_settings/hooks/use_my_settings.js +9 -0
  104. package/dist/components/layouts/my_settings/index.d.ts.map +1 -1
  105. package/dist/components/layouts/my_settings/index.js +4 -2
  106. package/dist/components/layouts/shared/components/google_icon.d.ts +12 -0
  107. package/dist/components/layouts/shared/components/google_icon.d.ts.map +1 -0
  108. package/dist/components/layouts/shared/components/google_icon.js +9 -0
  109. package/dist/components/layouts/shared/components/google_sign_in_button.d.ts +21 -0
  110. package/dist/components/layouts/shared/components/google_sign_in_button.d.ts.map +1 -0
  111. package/dist/components/layouts/shared/components/google_sign_in_button.js +50 -0
  112. package/dist/components/layouts/shared/components/oauth_divider.d.ts +13 -0
  113. package/dist/components/layouts/shared/components/oauth_divider.d.ts.map +1 -0
  114. package/dist/components/layouts/shared/components/oauth_divider.js +13 -0
  115. package/dist/components/layouts/shared/config/layout_customization.d.ts +2 -7
  116. package/dist/components/layouts/shared/config/layout_customization.d.ts.map +1 -1
  117. package/dist/components/layouts/shared/hooks/use_auth_status.d.ts +3 -0
  118. package/dist/components/layouts/shared/hooks/use_auth_status.d.ts.map +1 -1
  119. package/dist/components/layouts/shared/hooks/use_auth_status.js +4 -0
  120. package/dist/components/layouts/shared/index.d.ts +5 -0
  121. package/dist/components/layouts/shared/index.d.ts.map +1 -1
  122. package/dist/components/layouts/shared/index.js +3 -0
  123. package/dist/components/ui/button.d.ts +1 -1
  124. package/dist/lib/auth/nextauth_config.d.ts +34 -0
  125. package/dist/lib/auth/nextauth_config.d.ts.map +1 -0
  126. package/dist/lib/auth/nextauth_config.js +171 -0
  127. package/dist/lib/config/default_config.d.ts +24 -0
  128. package/dist/lib/config/default_config.d.ts.map +1 -1
  129. package/dist/lib/config/default_config.js +14 -0
  130. package/dist/lib/index.d.ts +2 -0
  131. package/dist/lib/index.d.ts.map +1 -1
  132. package/dist/lib/index.js +1 -0
  133. package/dist/lib/login_config.server.d.ts +3 -0
  134. package/dist/lib/login_config.server.d.ts.map +1 -1
  135. package/dist/lib/login_config.server.js +4 -0
  136. package/dist/lib/oauth_config.server.d.ts +29 -0
  137. package/dist/lib/oauth_config.server.d.ts.map +1 -0
  138. package/dist/lib/oauth_config.server.js +40 -0
  139. package/dist/lib/services/login_service.d.ts.map +1 -1
  140. package/dist/lib/services/login_service.js +16 -1
  141. package/dist/lib/services/oauth_service.d.ts +88 -0
  142. package/dist/lib/services/oauth_service.d.ts.map +1 -0
  143. package/dist/lib/services/oauth_service.js +376 -0
  144. package/dist/lib/services/password_reset_service.d.ts +2 -0
  145. package/dist/lib/services/password_reset_service.d.ts.map +1 -1
  146. package/dist/lib/services/password_reset_service.js +10 -0
  147. package/dist/lib/services/registration_service.d.ts.map +1 -1
  148. package/dist/lib/services/registration_service.js +1 -0
  149. package/dist/lib/utils/password_validator.d.ts +19 -0
  150. package/dist/lib/utils/password_validator.d.ts.map +1 -0
  151. package/dist/lib/utils/password_validator.js +36 -0
  152. package/dist/server_pages/login.d.ts.map +1 -1
  153. package/dist/server_pages/login.js +6 -1
  154. package/dist/server_pages/login_client_wrapper.d.ts +5 -2
  155. package/dist/server_pages/login_client_wrapper.d.ts.map +1 -1
  156. package/dist/server_pages/login_client_wrapper.js +2 -2
  157. package/package.json +6 -2
@@ -0,0 +1,101 @@
1
+ // file_description: singleton instance of hazo_connect adapter - initialized once and reused across all routes
2
+ // This ensures all routes/components use the same database connection
3
+ // Uses the new hazo_connect singleton API from hazo_connect/nextjs/setup
4
+ // Reads configuration from hazo_auth_config.ini using hazo_config
5
+ // section: imports
6
+ import type { HazoConnectAdapter } from "hazo_connect";
7
+ import { getHazoConnectSingleton } from "hazo_connect/nextjs/setup";
8
+ import { create_sqlite_hazo_connect_server, get_hazo_connect_config_options } from "./hazo_connect_setup.server";
9
+ import { initializeAdminService, getSqliteAdminService } from "hazo_connect/server";
10
+ import { create_app_logger } from "./app_logger";
11
+
12
+ // section: singleton_state
13
+ let hazoConnectInstance: HazoConnectAdapter | null = null;
14
+ let isInitialized = false;
15
+
16
+ // section: helpers
17
+ /**
18
+ * Gets or creates the singleton hazo_connect adapter instance
19
+ * This ensures all routes/components use the same database connection
20
+ *
21
+ * Uses the new hazo_connect singleton API which:
22
+ * - Automatically reuses the adapter instance
23
+ * - Automatically registers SQLite adapters with the admin service
24
+ * - Is thread-safe for Next.js serverless environments
25
+ * - Reads configuration from hazo_auth_config.ini using hazo_config (falls back to environment variables)
26
+ *
27
+ * Falls back to manual singleton if the new API is not available
28
+ *
29
+ * @returns The singleton HazoConnectAdapter instance
30
+ */
31
+ export function get_hazo_connect_instance(): HazoConnectAdapter {
32
+ // Use the new singleton API from hazo_connect
33
+ // This automatically handles:
34
+ // - Instance reuse
35
+ // - Admin service registration (via registerSqliteAdapter)
36
+ // - Thread-safety for Next.js serverless
37
+ // - Configuration from hazo_auth_config.ini (via hazo_config) or environment variables
38
+ try {
39
+ // Get configuration from hazo_auth_config.ini (falls back to environment variables)
40
+ const config_options = get_hazo_connect_config_options();
41
+ const logger = create_app_logger();
42
+ logger.debug("hazo_connect_singleton_attempt", {
43
+ filename: "hazo_connect_instance.server.ts",
44
+ line_number: 38,
45
+ config_options,
46
+ note: "Attempting to get singleton with these options",
47
+ });
48
+ return getHazoConnectSingleton(config_options);
49
+ } catch (error) {
50
+ const logger = create_app_logger();
51
+ const error_message = error instanceof Error ? error.message : "Unknown error";
52
+ logger.error("hazo_connect_singleton_failed", {
53
+ filename: "hazo_connect_instance.server.ts",
54
+ line_number: 45,
55
+ error: error_message,
56
+ error_stack: error instanceof Error ? error.stack : undefined,
57
+ note: "Falling back to manual singleton implementation",
58
+ });
59
+
60
+ // Fallback: Manual singleton implementation if new API fails
61
+ // This should not happen with the updated package, but kept for safety
62
+ if (!hazoConnectInstance) {
63
+ // Get config options to determine database type
64
+ const config_options = get_hazo_connect_config_options();
65
+ const db_type = config_options.type;
66
+
67
+ // Only initialize SQLite admin service for SQLite databases
68
+ if (db_type === "sqlite" && !isInitialized) {
69
+ initializeAdminService({ enable_admin_ui: true });
70
+ isInitialized = true;
71
+ }
72
+
73
+ // Create the adapter instance (reads from hazo_auth_config.ini)
74
+ // Note: Despite the name, this function supports both SQLite and PostgREST
75
+ hazoConnectInstance = create_sqlite_hazo_connect_server();
76
+
77
+ // Note: Database migrations should be applied manually via SQLite Admin UI
78
+ // or through a separate migration script. The token_service has fallback
79
+ // logic to work without the token_type column if migration hasn't been applied.
80
+
81
+ // Finalize initialization by getting the admin service (only for SQLite)
82
+ if (db_type === "sqlite") {
83
+ try {
84
+ getSqliteAdminService();
85
+ } catch (adminError) {
86
+ const logger = create_app_logger();
87
+ const error_message = adminError instanceof Error ? adminError.message : "Unknown error";
88
+ logger.warn("hazo_connect_instance_admin_service_init_failed", {
89
+ filename: "hazo_connect_instance.server.ts",
90
+ line_number: 0,
91
+ error: error_message,
92
+ note: "Could not get SqliteAdminService during initialization, continuing...",
93
+ });
94
+ }
95
+ }
96
+ }
97
+
98
+ return hazoConnectInstance;
99
+ }
100
+ }
101
+
@@ -0,0 +1,194 @@
1
+ // file_description: server-only helper to create hazo_connect instance (imports server-side code)
2
+ // This file should only be imported in server contexts (API routes, server components)
3
+ // Reads configuration from hazo_auth_config.ini using hazo_config
4
+ // section: imports
5
+ import { createHazoConnect } from "hazo_connect/server";
6
+ import { HazoConfig } from "hazo_config/dist/lib";
7
+ import path from "path";
8
+ import fs from "fs";
9
+ import { create_app_logger } from "./app_logger";
10
+ import { read_config_section } from "./config/config_loader.server";
11
+
12
+ // section: helpers
13
+ /**
14
+ * Reads hazo_connect configuration from hazo_auth_config.ini file
15
+ * Falls back to environment variables if hazo_auth_config.ini is not found or section is missing
16
+ * @returns Configuration options for hazo_connect
17
+ */
18
+ function get_hazo_connect_config(): {
19
+ type: "sqlite" | "postgrest";
20
+ sqlitePath?: string;
21
+ enableAdminUi: boolean;
22
+ readOnly?: boolean;
23
+ postgrestUrl?: string;
24
+ postgrestApiKey?: string;
25
+ } {
26
+ const default_config_path = path.resolve(process.cwd(), "hazo_auth_config.ini");
27
+ let hazo_connect_section: Record<string, string> | undefined;
28
+
29
+ // Try to read from hazo_auth_config.ini
30
+ const logger = create_app_logger();
31
+ hazo_connect_section = read_config_section("hazo_connect");
32
+
33
+ // Read type (defaults to sqlite)
34
+ const type = (
35
+ hazo_connect_section?.type ||
36
+ process.env.HAZO_CONNECT_TYPE ||
37
+ "sqlite"
38
+ ).toLowerCase() as "sqlite" | "postgrest";
39
+
40
+ // Read enable_admin_ui (defaults to true)
41
+ const enable_admin_ui_str =
42
+ hazo_connect_section?.enable_admin_ui ||
43
+ process.env.HAZO_CONNECT_ENABLE_ADMIN_UI ||
44
+ "true";
45
+ const enableAdminUi = enable_admin_ui_str.toLowerCase() === "true";
46
+
47
+ // Read read_only (defaults to false)
48
+ const read_only_str =
49
+ hazo_connect_section?.read_only ||
50
+ process.env.HAZO_CONNECT_SQLITE_READONLY ||
51
+ "false";
52
+ const readOnly = read_only_str.toLowerCase() === "true";
53
+
54
+ // SQLite configuration
55
+ if (type === "sqlite") {
56
+ const sqlite_path_config =
57
+ hazo_connect_section?.sqlite_path || process.env.HAZO_CONNECT_SQLITE_PATH;
58
+
59
+ let sqlite_path: string | undefined;
60
+
61
+ if (sqlite_path_config) {
62
+ // If path is absolute, use as-is; otherwise resolve relative to process.cwd()
63
+ sqlite_path = path.isAbsolute(sqlite_path_config)
64
+ ? sqlite_path_config
65
+ : path.resolve(process.cwd(), sqlite_path_config);
66
+
67
+ // Normalize the path to ensure consistency (resolves .., ., etc.)
68
+ sqlite_path = path.normalize(sqlite_path);
69
+ } else {
70
+ // Fallback to test fixture database
71
+ const fallback_sqlite_path = path.resolve(
72
+ process.cwd(),
73
+ "__tests__",
74
+ "fixtures",
75
+ "hazo_auth.sqlite"
76
+ );
77
+ sqlite_path = path.normalize(fallback_sqlite_path);
78
+ }
79
+
80
+ // Log the resolved path for debugging
81
+ logger.debug("hazo_connect_sqlite_path_resolved", {
82
+ filename: "hazo_connect_setup.server.ts",
83
+ line_number: 0,
84
+ sqlite_path,
85
+ process_cwd: process.cwd(),
86
+ config_source: hazo_connect_section ? "hazo_auth_config.ini" : "environment variables",
87
+ });
88
+
89
+ return {
90
+ type: "sqlite",
91
+ sqlitePath: sqlite_path,
92
+ enableAdminUi,
93
+ readOnly,
94
+ };
95
+ }
96
+
97
+ // PostgREST configuration
98
+ if (type === "postgrest") {
99
+ const postgrest_url =
100
+ hazo_connect_section?.postgrest_url ||
101
+ process.env.HAZO_CONNECT_POSTGREST_URL ||
102
+ process.env.POSTGREST_URL;
103
+ // API key must only come from environment variables for security
104
+ // Check multiple possible env var names for compatibility
105
+ const postgrest_api_key =
106
+ process.env.postgrest_api_key || // hazo_connect package expects this
107
+ process.env.HAZO_CONNECT_POSTGREST_API_KEY ||
108
+ process.env.POSTGREST_API_KEY;
109
+
110
+ if (!postgrest_url) {
111
+ throw new Error(
112
+ "PostgREST URL is required. Set postgrest_url in [hazo_connect] section of hazo_auth_config.ini or HAZO_CONNECT_POSTGREST_URL environment variable."
113
+ );
114
+ }
115
+
116
+ return {
117
+ type: "postgrest",
118
+ postgrestUrl: postgrest_url,
119
+ postgrestApiKey: postgrest_api_key,
120
+ enableAdminUi,
121
+ };
122
+ }
123
+
124
+ throw new Error(
125
+ `Unsupported HAZO_CONNECT_TYPE: ${type}. Supported types: sqlite, postgrest`
126
+ );
127
+ }
128
+
129
+ /**
130
+ * Server-only function to create hazo_connect adapter
131
+ * Reads configuration from hazo_auth_config.ini using hazo_config, falls back to environment variables
132
+ * This should only be called from server-side code (API routes, server components)
133
+ */
134
+ export function create_sqlite_hazo_connect_server() {
135
+ const config = get_hazo_connect_config();
136
+
137
+ if (config.type === "sqlite") {
138
+ return createHazoConnect({
139
+ type: "sqlite",
140
+ database: config.sqlitePath!,
141
+ enable_admin_ui: config.enableAdminUi,
142
+ });
143
+ }
144
+
145
+ if (config.type === "postgrest") {
146
+ // Ensure we have a value (empty string if not set, for PostgREST instances without auth)
147
+ const apiKey = config.postgrestApiKey || "";
148
+
149
+ return createHazoConnect({
150
+ type: "postgrest",
151
+ baseUrl: config.postgrestUrl!,
152
+ apiKey: apiKey, // Pass empty string if not set
153
+ });
154
+ }
155
+
156
+ throw new Error(`Unsupported database type: ${config.type}`);
157
+ }
158
+
159
+ /**
160
+ * Gets hazo_connect configuration options for use with singleton API
161
+ * Reads from hazo_auth_config.ini using hazo_config, falls back to environment variables
162
+ * @returns Configuration options compatible with getHazoConnectSingleton
163
+ */
164
+ export function get_hazo_connect_config_options(): {
165
+ type?: "sqlite" | "postgrest";
166
+ sqlitePath?: string;
167
+ enableAdminUi?: boolean;
168
+ readOnly?: boolean;
169
+ baseUrl?: string;
170
+ apiKey?: string;
171
+ } {
172
+ const config = get_hazo_connect_config();
173
+
174
+ if (config.type === "sqlite") {
175
+ return {
176
+ type: "sqlite",
177
+ sqlitePath: config.sqlitePath,
178
+ enableAdminUi: config.enableAdminUi,
179
+ readOnly: config.readOnly,
180
+ };
181
+ }
182
+
183
+ if (config.type === "postgrest") {
184
+ return {
185
+ type: "postgrest",
186
+ baseUrl: config.postgrestUrl, // Corrected from postgrestUrl
187
+ apiKey: config.postgrestApiKey || "", // Corrected from postgrestApiKey and ensured string value
188
+ };
189
+ }
190
+
191
+ // Fallback: return empty object to let it use environment variables
192
+ return {};
193
+ }
194
+
@@ -0,0 +1,54 @@
1
+ // file_description: helper function to create hazo_connect instance with configuration from environment variables
2
+ // This file provides a client-safe wrapper that returns a mock on client-side
3
+ // section: imports
4
+ // Note: We don't import server-side code here to avoid client-side bundling issues
5
+
6
+ // section: helpers
7
+ /**
8
+ * Creates a hazo_connect instance configured from environment variables
9
+ *
10
+ * Environment variables:
11
+ * - HAZO_CONNECT_TYPE: Database type ("sqlite" | "postgrest") - defaults to "sqlite"
12
+ * - HAZO_CONNECT_SQLITE_PATH: Path to SQLite database file (relative to process.cwd() or absolute)
13
+ * - HAZO_CONNECT_POSTGREST_URL: PostgREST API URL (for postgrest type)
14
+ * - HAZO_CONNECT_POSTGREST_API_KEY: PostgREST API key (for postgrest type)
15
+ *
16
+ * Falls back to test fixture database if HAZO_CONNECT_SQLITE_PATH is not set
17
+ *
18
+ * Note: For client-side usage (Next.js pages), this returns a mock adapter
19
+ * since SQLite cannot run in browser environments. Use PostgREST for client-side database access.
20
+ */
21
+ // Lazy loader for server module - prevents webpack from statically analyzing the require
22
+ function loadServerModule() {
23
+ // Use Function constructor to create a dynamic require that webpack can't analyze
24
+ // eslint-disable-next-line no-new-func
25
+ const requireFunc = new Function('modulePath', 'return require(modulePath)');
26
+ return requireFunc('./hazo_connect_setup.server');
27
+ }
28
+
29
+ export function create_sqlite_hazo_connect() {
30
+ // Check if we're in a browser/client environment
31
+ if (typeof window !== "undefined") {
32
+ // Return a mock adapter for client-side usage
33
+ return create_client_mock_hazo_connect();
34
+ }
35
+
36
+ // Server-side: dynamically load server module
37
+ // Using Function constructor prevents webpack from statically analyzing the require
38
+ const serverModule = loadServerModule();
39
+ return serverModule.create_sqlite_hazo_connect_server();
40
+ }
41
+
42
+ /**
43
+ * Creates a mock hazo_connect adapter for client-side usage
44
+ * This satisfies the LayoutDataClient interface without requiring SQLite
45
+ */
46
+ function create_client_mock_hazo_connect() {
47
+ return {
48
+ healthCheck: async () => {
49
+ // Mock health check for client-side - no-op
50
+ return Promise.resolve();
51
+ },
52
+ };
53
+ }
54
+
@@ -0,0 +1,46 @@
1
+ // file_description: barrel export for lib utilities
2
+ // section: auth_exports
3
+ export * from "./auth/index";
4
+
5
+ // section: service_exports
6
+ export * from "./services/index";
7
+
8
+ // section: utility_exports
9
+ export { cn, merge_class_names } from "./utils";
10
+
11
+ // section: config_exports
12
+ export { get_config_value, get_config_number, get_config_boolean, get_config_array, read_config_section } from "./config/config_loader.server";
13
+
14
+ // section: hazo_connect_exports
15
+ export { create_sqlite_hazo_connect } from "./hazo_connect_setup";
16
+ export { get_hazo_connect_instance } from "./hazo_connect_instance.server";
17
+
18
+ // section: logger_exports
19
+ export { create_app_logger } from "./app_logger";
20
+
21
+ // section: config_server_exports
22
+ export { get_login_config } from "./login_config.server";
23
+ export { get_register_config } from "./register_config.server";
24
+ export { get_forgot_password_config } from "./forgot_password_config.server";
25
+ export { get_reset_password_config } from "./reset_password_config.server";
26
+ export { get_email_verification_config } from "./email_verification_config.server";
27
+ export { get_my_settings_config } from "./my_settings_config.server";
28
+ export { get_user_management_config } from "./user_management_config.server";
29
+ export { get_profile_picture_config } from "./profile_picture_config.server";
30
+ export { get_profile_pic_menu_config } from "./profile_pic_menu_config.server";
31
+ export { get_already_logged_in_config } from "./already_logged_in_config.server";
32
+ export { get_ui_shell_config } from "./ui_shell_config.server";
33
+ export { get_ui_sizes_config } from "./ui_sizes_config.server";
34
+ export { get_auth_utility_config } from "./auth_utility_config.server";
35
+ export { get_password_requirements_config } from "./password_requirements_config.server";
36
+ export { get_messages_config } from "./messages_config.server";
37
+ export { get_user_fields_config } from "./user_fields_config.server";
38
+ export { get_file_types_config } from "./file_types_config.server";
39
+ export { get_oauth_config, is_google_oauth_enabled, is_email_password_enabled } from "./oauth_config.server";
40
+ export type { OAuthConfig } from "./oauth_config.server";
41
+
42
+ // section: util_exports
43
+ export { sanitize_error_for_user } from "./utils/error_sanitizer";
44
+ export type { ErrorSanitizationOptions } from "./utils/error_sanitizer";
45
+ export * from "./utils/api_route_helpers";
46
+
@@ -0,0 +1,106 @@
1
+ // file_description: server-only helper to read login layout configuration from hazo_auth_config.ini
2
+ // section: imports
3
+ import { get_config_value } from "./config/config_loader.server";
4
+ import { get_already_logged_in_config } from "./already_logged_in_config.server";
5
+ import { get_oauth_config, type OAuthConfig } from "./oauth_config.server";
6
+ import loginDefaultImage from "../assets/images/login_default.jpg";
7
+
8
+ // section: types
9
+ import type { StaticImageData } from "next/image";
10
+
11
+ export type LoginConfig = {
12
+ redirectRoute?: string;
13
+ successMessage: string;
14
+ alreadyLoggedInMessage: string;
15
+ showLogoutButton: boolean;
16
+ showReturnHomeButton: boolean;
17
+ returnHomeButtonLabel: string;
18
+ returnHomePath: string;
19
+ forgotPasswordPath: string;
20
+ forgotPasswordLabel: string;
21
+ createAccountPath: string;
22
+ createAccountLabel: string;
23
+ imageSrc: string | StaticImageData;
24
+ imageAlt: string;
25
+ imageBackgroundColor: string;
26
+ /** OAuth configuration */
27
+ oauth: OAuthConfig;
28
+ };
29
+
30
+ // section: helpers
31
+ /**
32
+ * Reads login layout configuration from hazo_auth_config.ini file
33
+ * Falls back to defaults if hazo_auth_config.ini is not found or section is missing
34
+ * @returns Login configuration options
35
+ */
36
+ export function get_login_config(): LoginConfig {
37
+ const section = "hazo_auth__login_layout";
38
+
39
+ // Read redirect route (optional)
40
+ const redirectRouteValue = get_config_value(section, "redirect_route_on_successful_login", "");
41
+ const redirectRoute = redirectRouteValue || undefined;
42
+
43
+ // Read success message (defaults to "Successfully logged in")
44
+ const successMessage = get_config_value(section, "success_message", "Successfully logged in");
45
+
46
+ const forgotPasswordPath = get_config_value(
47
+ section,
48
+ "forgot_password_path",
49
+ "/hazo_auth/forgot_password"
50
+ );
51
+ const forgotPasswordLabel = get_config_value(
52
+ section,
53
+ "forgot_password_label",
54
+ "Forgot password?"
55
+ );
56
+ const createAccountPath = get_config_value(section, "create_account_path", "/hazo_auth/register");
57
+ const createAccountLabel = get_config_value(
58
+ section,
59
+ "create_account_label",
60
+ "Create account"
61
+ );
62
+
63
+ // Get shared already logged in config
64
+ const alreadyLoggedInConfig = get_already_logged_in_config();
65
+
66
+ // Read image configuration
67
+ // If not set in config, falls back to default image from assets
68
+ const imageSrc = get_config_value(
69
+ section,
70
+ "image_src",
71
+ "" // Empty string means not set in config
72
+ ) || loginDefaultImage;
73
+
74
+ const imageAlt = get_config_value(
75
+ section,
76
+ "image_alt",
77
+ "Secure login illustration"
78
+ );
79
+ const imageBackgroundColor = get_config_value(
80
+ section,
81
+ "image_background_color",
82
+ "#f1f5f9"
83
+ );
84
+
85
+ // Get OAuth configuration
86
+ const oauth = get_oauth_config();
87
+
88
+ return {
89
+ redirectRoute,
90
+ successMessage,
91
+ alreadyLoggedInMessage: alreadyLoggedInConfig.message,
92
+ showLogoutButton: alreadyLoggedInConfig.showLogoutButton,
93
+ showReturnHomeButton: alreadyLoggedInConfig.showReturnHomeButton,
94
+ returnHomeButtonLabel: alreadyLoggedInConfig.returnHomeButtonLabel,
95
+ returnHomePath: alreadyLoggedInConfig.returnHomePath,
96
+ forgotPasswordPath,
97
+ forgotPasswordLabel,
98
+ createAccountPath,
99
+ createAccountLabel,
100
+ imageSrc,
101
+ imageAlt,
102
+ imageBackgroundColor,
103
+ oauth,
104
+ };
105
+ }
106
+
@@ -0,0 +1,45 @@
1
+ // file_description: server-only helper to read user-facing messages from hazo_auth_config.ini
2
+ // section: imports
3
+ import { get_config_value } from "./config/config_loader.server";
4
+
5
+ // section: types
6
+ export type MessagesConfig = {
7
+ photo_upload_disabled_message: string;
8
+ gravatar_setup_message: string;
9
+ gravatar_no_account_message: string;
10
+ library_tooltip_message: string;
11
+ };
12
+
13
+ // section: helpers
14
+ /**
15
+ * Reads user-facing messages from hazo_auth_config.ini file
16
+ * Falls back to defaults if hazo_auth_config.ini is not found or section is missing
17
+ * @returns Messages configuration options
18
+ */
19
+ export function get_messages_config(): MessagesConfig {
20
+ const section = "hazo_auth__messages";
21
+
22
+ return {
23
+ photo_upload_disabled_message: get_config_value(
24
+ section,
25
+ "photo_upload_disabled_message",
26
+ "Photo upload is not enabled. Please contact your administrator."
27
+ ),
28
+ gravatar_setup_message: get_config_value(
29
+ section,
30
+ "gravatar_setup_message",
31
+ "To set up your Gravatar:"
32
+ ),
33
+ gravatar_no_account_message: get_config_value(
34
+ section,
35
+ "gravatar_no_account_message",
36
+ "You don't have a Gravatar account set up for this email address."
37
+ ),
38
+ library_tooltip_message: get_config_value(
39
+ section,
40
+ "library_tooltip_message",
41
+ "Select another tab image style to remove this image"
42
+ ),
43
+ };
44
+ }
45
+
@@ -0,0 +1,105 @@
1
+ // file_description: helper to apply database migrations using hazo_connect
2
+ // section: imports
3
+ import type { HazoConnectAdapter } from "hazo_connect";
4
+ import { createCrudService } from "hazo_connect/server";
5
+ import fs from "fs";
6
+ import path from "path";
7
+
8
+ // section: helpers
9
+ /**
10
+ * Applies a SQL migration file to the database
11
+ * For SQLite, we need to execute raw SQL statements
12
+ * @param adapter - The hazo_connect adapter instance
13
+ * @param migration_file_path - Path to the SQL migration file
14
+ * @returns Success status and error message if any
15
+ */
16
+ export async function apply_migration(
17
+ adapter: HazoConnectAdapter,
18
+ migration_file_path: string,
19
+ ): Promise<{ success: boolean; error?: string }> {
20
+ try {
21
+ // Read the migration file
22
+ const migration_sql = fs.readFileSync(migration_file_path, "utf-8");
23
+
24
+ // Split SQL statements by semicolon and execute each one
25
+ // Remove comments and empty statements
26
+ const statements = migration_sql
27
+ .split(";")
28
+ .map((stmt) => stmt.trim())
29
+ .filter((stmt) => stmt.length > 0 && !stmt.startsWith("--"));
30
+
31
+ // Execute each statement
32
+ // For SQLite via hazo_connect, we may need to use a raw query method
33
+ // Since hazo_connect doesn't expose raw SQL execution directly,
34
+ // we'll try to use the adapter's internal methods or skip migration
35
+ // and rely on the fallback in token_service
36
+
37
+ // For now, we'll log that migration should be applied manually
38
+ // The token_service has fallback logic to work without token_type column
39
+ if (process.env.NODE_ENV === "development") {
40
+ console.log(
41
+ `[migrations] Migration file found: ${migration_file_path}`,
42
+ "\n[migrations] Note: Raw SQL execution not available via hazo_connect adapter.",
43
+ "\n[migrations] Please apply migration manually or ensure token_type column exists."
44
+ );
45
+ }
46
+
47
+ // Try to check if token_type column already exists by querying the schema
48
+ // If it doesn't exist, we'll rely on the fallback in token_service
49
+ return { success: true };
50
+ } catch (error) {
51
+ const error_message =
52
+ error instanceof Error ? error.message : "Unknown error";
53
+
54
+ return {
55
+ success: false,
56
+ error: error_message,
57
+ };
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Applies all migrations in the migrations directory
63
+ * @param adapter - The hazo_connect adapter instance
64
+ * @returns Success status and error message if any
65
+ */
66
+ export async function apply_all_migrations(
67
+ adapter: HazoConnectAdapter,
68
+ ): Promise<{ success: boolean; error?: string }> {
69
+ try {
70
+ const migrations_dir = path.resolve(process.cwd(), "migrations");
71
+
72
+ if (!fs.existsSync(migrations_dir)) {
73
+ return { success: true }; // No migrations directory, nothing to apply
74
+ }
75
+
76
+ // Get all SQL files in migrations directory, sorted by name
77
+ const migration_files = fs
78
+ .readdirSync(migrations_dir)
79
+ .filter((file) => file.endsWith(".sql"))
80
+ .sort();
81
+
82
+ for (const migration_file of migration_files) {
83
+ const migration_path = path.join(migrations_dir, migration_file);
84
+ const result = await apply_migration(adapter, migration_path);
85
+
86
+ if (!result.success) {
87
+ return {
88
+ success: false,
89
+ error: `Failed to apply migration ${migration_file}: ${result.error}`,
90
+ };
91
+ }
92
+ }
93
+
94
+ return { success: true };
95
+ } catch (error) {
96
+ const error_message =
97
+ error instanceof Error ? error.message : "Unknown error";
98
+
99
+ return {
100
+ success: false,
101
+ error: error_message,
102
+ };
103
+ }
104
+ }
105
+