hazo_auth 1.0.4 → 1.1.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 (108) hide show
  1. package/README.md +72 -1
  2. package/hazo_auth_config.example.ini +41 -0
  3. package/instrumentation.ts +2 -2
  4. package/package.json +4 -3
  5. package/scripts/init_users.ts +378 -0
  6. package/src/app/api/hazo_auth/auth/upload_profile_picture/route.ts +8 -8
  7. package/src/app/api/hazo_auth/change_password/route.ts +7 -7
  8. package/src/app/api/hazo_auth/forgot_password/route.ts +4 -4
  9. package/src/app/api/hazo_auth/get_auth/route.ts +4 -4
  10. package/src/app/api/hazo_auth/invalidate_cache/route.ts +5 -5
  11. package/src/app/api/hazo_auth/library_photos/route.ts +3 -3
  12. package/src/app/api/hazo_auth/login/route.ts +31 -5
  13. package/src/app/api/hazo_auth/logout/route.ts +4 -4
  14. package/src/app/api/hazo_auth/me/route.ts +1 -1
  15. package/src/app/api/hazo_auth/profile_picture/[filename]/route.ts +1 -1
  16. package/src/app/api/hazo_auth/register/route.ts +17 -14
  17. package/src/app/api/hazo_auth/remove_profile_picture/route.ts +5 -5
  18. package/src/app/api/hazo_auth/resend_verification/route.ts +4 -4
  19. package/src/app/api/hazo_auth/reset_password/route.ts +5 -5
  20. package/src/app/api/hazo_auth/update_user/route.ts +5 -5
  21. package/src/app/api/hazo_auth/upload_profile_picture/route.ts +8 -8
  22. package/src/app/api/hazo_auth/user_management/permissions/route.ts +4 -4
  23. package/src/app/api/hazo_auth/user_management/roles/route.ts +5 -5
  24. package/src/app/api/hazo_auth/user_management/users/roles/route.ts +5 -5
  25. package/src/app/api/hazo_auth/user_management/users/route.ts +6 -6
  26. package/src/app/api/hazo_auth/validate_reset_token/route.ts +4 -4
  27. package/src/app/api/hazo_auth/verify_email/route.ts +4 -4
  28. package/src/app/api/migrations/apply/route.ts +3 -3
  29. package/src/app/hazo_auth/forgot_password/forgot_password_page_client.tsx +4 -4
  30. package/src/app/hazo_auth/forgot_password/page.tsx +4 -4
  31. package/src/app/hazo_auth/login/login_page_client.tsx +20 -5
  32. package/src/app/hazo_auth/login/page.tsx +17 -5
  33. package/src/app/hazo_auth/my_settings/my_settings_page_client.tsx +3 -3
  34. package/src/app/hazo_auth/my_settings/page.tsx +4 -4
  35. package/src/app/hazo_auth/register/page.tsx +15 -5
  36. package/src/app/hazo_auth/register/register_page_client.tsx +13 -4
  37. package/src/app/hazo_auth/reset_password/page.tsx +4 -4
  38. package/src/app/hazo_auth/reset_password/reset_password_page_client.tsx +4 -4
  39. package/src/app/hazo_auth/user_management/page.tsx +3 -3
  40. package/src/app/hazo_auth/user_management/user_management_page_client.tsx +1 -1
  41. package/src/app/hazo_auth/verify_email/page.tsx +4 -4
  42. package/src/app/hazo_auth/verify_email/verify_email_page_client.tsx +4 -4
  43. package/src/app/hazo_connect/api/sqlite/data/route.ts +1 -1
  44. package/src/app/hazo_connect/api/sqlite/schema/route.ts +1 -1
  45. package/src/app/hazo_connect/api/sqlite/tables/route.ts +1 -1
  46. package/src/app/layout.tsx +1 -1
  47. package/src/app/page.tsx +1 -1
  48. package/src/components/layouts/email_verification/config/email_verification_field_config.ts +2 -2
  49. package/src/components/layouts/email_verification/hooks/use_email_verification.ts +3 -3
  50. package/src/components/layouts/email_verification/index.tsx +11 -11
  51. package/src/components/layouts/forgot_password/config/forgot_password_field_config.ts +2 -2
  52. package/src/components/layouts/forgot_password/hooks/use_forgot_password_form.ts +3 -3
  53. package/src/components/layouts/forgot_password/index.tsx +10 -10
  54. package/src/components/layouts/login/config/login_field_config.ts +2 -2
  55. package/src/components/layouts/login/hooks/use_login_form.ts +18 -13
  56. package/src/components/layouts/login/index.tsx +39 -11
  57. package/src/components/layouts/my_settings/components/editable_field.tsx +3 -3
  58. package/src/components/layouts/my_settings/components/password_change_dialog.tsx +5 -5
  59. package/src/components/layouts/my_settings/components/profile_picture_dialog.tsx +4 -4
  60. package/src/components/layouts/my_settings/components/profile_picture_display.tsx +2 -2
  61. package/src/components/layouts/my_settings/components/profile_picture_gravatar_tab.tsx +3 -3
  62. package/src/components/layouts/my_settings/components/profile_picture_library_tab.tsx +5 -5
  63. package/src/components/layouts/my_settings/components/profile_picture_upload_tab.tsx +4 -4
  64. package/src/components/layouts/my_settings/config/my_settings_field_config.ts +2 -2
  65. package/src/components/layouts/my_settings/hooks/use_my_settings.ts +2 -2
  66. package/src/components/layouts/my_settings/index.tsx +5 -5
  67. package/src/components/layouts/register/config/register_field_config.ts +2 -2
  68. package/src/components/layouts/register/hooks/use_register_form.ts +8 -5
  69. package/src/components/layouts/register/index.tsx +29 -11
  70. package/src/components/layouts/reset_password/config/reset_password_field_config.ts +2 -2
  71. package/src/components/layouts/reset_password/hooks/use_reset_password_form.ts +4 -4
  72. package/src/components/layouts/reset_password/index.tsx +10 -10
  73. package/src/components/layouts/shared/components/auth_page_shell.tsx +36 -0
  74. package/src/components/layouts/shared/components/standalone_layout_wrapper.tsx +53 -0
  75. package/src/components/layouts/user_management/components/roles_matrix.tsx +7 -7
  76. package/src/components/layouts/user_management/index.tsx +10 -10
  77. package/src/components/ui/alert-dialog.tsx +2 -2
  78. package/src/components/ui/avatar.tsx +1 -1
  79. package/src/components/ui/button.tsx +1 -1
  80. package/src/components/ui/checkbox.tsx +1 -1
  81. package/src/components/ui/dialog.tsx +1 -1
  82. package/src/components/ui/dropdown-menu.tsx +1 -1
  83. package/src/components/ui/hazo_ui_tooltip.tsx +1 -1
  84. package/src/components/ui/input.tsx +1 -1
  85. package/src/components/ui/label.tsx +1 -1
  86. package/src/components/ui/separator.tsx +1 -1
  87. package/src/components/ui/sheet.tsx +1 -1
  88. package/src/components/ui/sidebar.tsx +8 -8
  89. package/src/components/ui/skeleton.tsx +1 -1
  90. package/src/components/ui/switch.tsx +1 -1
  91. package/src/components/ui/table.tsx +1 -1
  92. package/src/components/ui/tabs.tsx +1 -1
  93. package/src/components/ui/tooltip.tsx +1 -1
  94. package/src/components/ui/vertical-tabs.tsx +1 -1
  95. package/src/lib/app_logger.ts +1 -1
  96. package/src/lib/config/config_loader.server.ts +20 -5
  97. package/src/lib/login_config.server.ts +25 -0
  98. package/src/lib/register_config.server.ts +17 -1
  99. package/src/lib/services/login_service.ts +19 -3
  100. package/src/lib/services/registration_service.ts +25 -4
  101. package/src/lib/services/user_update_service.ts +16 -3
  102. package/src/lib/ui_shell_config.server.ts +73 -0
  103. package/src/lib/utils/error_sanitizer.ts +75 -0
  104. package/src/stories/email_verification_layout.stories.tsx +2 -2
  105. package/src/stories/forgot_password_layout.stories.tsx +2 -2
  106. package/src/stories/login_layout.stories.tsx +2 -2
  107. package/src/stories/register_layout.stories.tsx +2 -2
  108. package/tsconfig.json +1 -4
@@ -4,7 +4,7 @@ import * as React from "react"
4
4
  import * as LabelPrimitive from "@radix-ui/react-label"
5
5
  import { cva, type VariantProps } from "class-variance-authority"
6
6
 
7
- import { cn } from "@/lib/utils"
7
+ import { cn } from "../../lib/utils"
8
8
 
9
9
  const labelVariants = cva(
10
10
  "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
@@ -3,7 +3,7 @@
3
3
  import * as React from "react"
4
4
  import * as SeparatorPrimitive from "@radix-ui/react-separator"
5
5
 
6
- import { cn } from "@/lib/utils"
6
+ import { cn } from "../../lib/utils"
7
7
 
8
8
  const Separator = React.forwardRef<
9
9
  React.ElementRef<typeof SeparatorPrimitive.Root>,
@@ -5,7 +5,7 @@ import * as SheetPrimitive from "@radix-ui/react-dialog"
5
5
  import { cva, type VariantProps } from "class-variance-authority"
6
6
  import { X } from "lucide-react"
7
7
 
8
- import { cn } from "@/lib/utils"
8
+ import { cn } from "../../lib/utils"
9
9
 
10
10
  const Sheet = SheetPrimitive.Root
11
11
 
@@ -5,25 +5,25 @@ import { Slot } from "@radix-ui/react-slot"
5
5
  import { cva, type VariantProps } from "class-variance-authority"
6
6
  import { PanelLeft } from "lucide-react"
7
7
 
8
- import { useIsMobile } from "@/hooks/use-mobile"
9
- import { cn } from "@/lib/utils"
10
- import { Button } from "@/components/ui/button"
11
- import { Input } from "@/components/ui/input"
12
- import { Separator } from "@/components/ui/separator"
8
+ import { useIsMobile } from "../../hooks/use-mobile"
9
+ import { cn } from "../../lib/utils"
10
+ import { Button } from "./button"
11
+ import { Input } from "./input"
12
+ import { Separator } from "./separator"
13
13
  import {
14
14
  Sheet,
15
15
  SheetContent,
16
16
  SheetDescription,
17
17
  SheetHeader,
18
18
  SheetTitle,
19
- } from "@/components/ui/sheet"
20
- import { Skeleton } from "@/components/ui/skeleton"
19
+ } from "./sheet"
20
+ import { Skeleton } from "./skeleton"
21
21
  import {
22
22
  Tooltip,
23
23
  TooltipContent,
24
24
  TooltipProvider,
25
25
  TooltipTrigger,
26
- } from "@/components/ui/tooltip"
26
+ } from "./tooltip"
27
27
 
28
28
  const SIDEBAR_COOKIE_NAME = "sidebar_state"
29
29
  const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
@@ -1,4 +1,4 @@
1
- import { cn } from "@/lib/utils"
1
+ import { cn } from "../../lib/utils"
2
2
 
3
3
  function Skeleton({
4
4
  className,
@@ -3,7 +3,7 @@
3
3
  import * as React from "react"
4
4
  import * as SwitchPrimitives from "@radix-ui/react-switch"
5
5
 
6
- import { cn } from "@/lib/utils"
6
+ import { cn } from "../../lib/utils"
7
7
 
8
8
  const Switch = React.forwardRef<
9
9
  React.ElementRef<typeof SwitchPrimitives.Root>,
@@ -1,6 +1,6 @@
1
1
  import * as React from "react"
2
2
 
3
- import { cn } from "@/lib/utils"
3
+ import { cn } from "../../lib/utils"
4
4
 
5
5
  const Table = React.forwardRef<
6
6
  HTMLTableElement,
@@ -3,7 +3,7 @@
3
3
  import * as React from "react"
4
4
  import * as TabsPrimitive from "@radix-ui/react-tabs"
5
5
 
6
- import { cn } from "@/lib/utils"
6
+ import { cn } from "../../lib/utils"
7
7
 
8
8
  const Tabs = TabsPrimitive.Root
9
9
 
@@ -3,7 +3,7 @@
3
3
  import * as React from "react"
4
4
  import * as TooltipPrimitive from "@radix-ui/react-tooltip"
5
5
 
6
- import { cn } from "@/lib/utils"
6
+ import { cn } from "../../lib/utils"
7
7
 
8
8
  const TooltipProvider = TooltipPrimitive.Provider
9
9
 
@@ -5,7 +5,7 @@
5
5
  // section: imports
6
6
  import * as React from "react";
7
7
  import * as TabsPrimitive from "@radix-ui/react-tabs";
8
- import { cn } from "@/lib/utils";
8
+ import { cn } from "../../lib/utils";
9
9
 
10
10
  // section: components
11
11
  const VerticalTabs = TabsPrimitive.Root;
@@ -1,6 +1,6 @@
1
1
  // file_description: client-accessible wrapper for the main app logging service
2
2
  // section: imports
3
- import { create_logger_service } from "@/server/logging/logger_service";
3
+ import { create_logger_service } from "../server/logging/logger_service";
4
4
 
5
5
  // section: constants
6
6
  const APP_NAMESPACE = "hazo_auth_ui";
@@ -71,7 +71,12 @@ export function get_config_value(
71
71
  file_path?: string,
72
72
  ): string {
73
73
  const section = read_config_section(section_name, file_path);
74
- return section?.[key]?.trim() || default_value;
74
+ // Optional chaining on section and section[key]
75
+ // If section is undefined, or key is undefined, fall back to default
76
+ if (!section || section[key] === undefined) {
77
+ return default_value;
78
+ }
79
+ return section[key].trim() || default_value;
75
80
  }
76
81
 
77
82
  /**
@@ -89,12 +94,12 @@ export function get_config_boolean(
89
94
  file_path?: string,
90
95
  ): boolean {
91
96
  const section = read_config_section(section_name, file_path);
92
- const value = section?.[key]?.trim().toLowerCase();
93
97
 
94
- if (value === undefined) {
98
+ if (!section || section[key] === undefined) {
95
99
  return default_value;
96
100
  }
97
101
 
102
+ const value = section[key].trim().toLowerCase();
98
103
  return value !== "false" && value !== "0" && value !== "";
99
104
  }
100
105
 
@@ -113,7 +118,12 @@ export function get_config_number(
113
118
  file_path?: string,
114
119
  ): number {
115
120
  const section = read_config_section(section_name, file_path);
116
- const value = section?.[key]?.trim();
121
+
122
+ if (!section || section[key] === undefined) {
123
+ return default_value;
124
+ }
125
+
126
+ const value = section[key].trim();
117
127
 
118
128
  if (!value) {
119
129
  return default_value;
@@ -138,7 +148,12 @@ export function get_config_array(
138
148
  file_path?: string,
139
149
  ): string[] {
140
150
  const section = read_config_section(section_name, file_path);
141
- const value = section?.[key]?.trim();
151
+
152
+ if (!section || section[key] === undefined) {
153
+ return default_value;
154
+ }
155
+
156
+ const value = section[key].trim();
142
157
 
143
158
  if (!value) {
144
159
  return default_value;
@@ -12,6 +12,10 @@ export type LoginConfig = {
12
12
  showReturnHomeButton: boolean;
13
13
  returnHomeButtonLabel: string;
14
14
  returnHomePath: string;
15
+ forgotPasswordPath: string;
16
+ forgotPasswordLabel: string;
17
+ createAccountPath: string;
18
+ createAccountLabel: string;
15
19
  };
16
20
 
17
21
  // section: helpers
@@ -30,6 +34,23 @@ export function get_login_config(): LoginConfig {
30
34
  // Read success message (defaults to "Successfully logged in")
31
35
  const successMessage = get_config_value(section, "success_message", "Successfully logged in");
32
36
 
37
+ const forgotPasswordPath = get_config_value(
38
+ section,
39
+ "forgot_password_path",
40
+ "/hazo_auth/forgot_password"
41
+ );
42
+ const forgotPasswordLabel = get_config_value(
43
+ section,
44
+ "forgot_password_label",
45
+ "Forgot password?"
46
+ );
47
+ const createAccountPath = get_config_value(section, "create_account_path", "/hazo_auth/register");
48
+ const createAccountLabel = get_config_value(
49
+ section,
50
+ "create_account_label",
51
+ "Create account"
52
+ );
53
+
33
54
  // Get shared already logged in config
34
55
  const alreadyLoggedInConfig = get_already_logged_in_config();
35
56
 
@@ -41,6 +62,10 @@ export function get_login_config(): LoginConfig {
41
62
  showReturnHomeButton: alreadyLoggedInConfig.showReturnHomeButton,
42
63
  returnHomeButtonLabel: alreadyLoggedInConfig.returnHomeButtonLabel,
43
64
  returnHomePath: alreadyLoggedInConfig.returnHomePath,
65
+ forgotPasswordPath,
66
+ forgotPasswordLabel,
67
+ createAccountPath,
68
+ createAccountLabel,
44
69
  };
45
70
  }
46
71
 
@@ -1,6 +1,6 @@
1
1
  // file_description: server-only helper to read register layout configuration from hazo_auth_config.ini
2
2
  // section: imports
3
- import { get_config_boolean, read_config_section } from "./config/config_loader.server";
3
+ import { get_config_boolean, get_config_value, read_config_section } from "./config/config_loader.server";
4
4
  import { get_password_requirements_config } from "./password_requirements_config.server";
5
5
  import { get_already_logged_in_config } from "./already_logged_in_config.server";
6
6
  import { get_user_fields_config } from "./user_fields_config.server";
@@ -20,6 +20,8 @@ export type RegisterConfig = {
20
20
  showReturnHomeButton: boolean;
21
21
  returnHomeButtonLabel: string;
22
22
  returnHomePath: string;
23
+ signInPath: string;
24
+ signInLabel: string;
23
25
  };
24
26
 
25
27
  // section: helpers
@@ -44,6 +46,18 @@ export function get_register_config(): RegisterConfig {
44
46
  // Get shared already logged in config
45
47
  const alreadyLoggedInConfig = get_already_logged_in_config();
46
48
 
49
+ // Read sign in link configuration
50
+ const signInPath = get_config_value(
51
+ "hazo_auth__register_layout",
52
+ "sign_in_path",
53
+ "/hazo_auth/login"
54
+ );
55
+ const signInLabel = get_config_value(
56
+ "hazo_auth__register_layout",
57
+ "sign_in_label",
58
+ "Sign in"
59
+ );
60
+
47
61
  return {
48
62
  showNameField,
49
63
  passwordRequirements,
@@ -52,6 +66,8 @@ export function get_register_config(): RegisterConfig {
52
66
  showReturnHomeButton: alreadyLoggedInConfig.showReturnHomeButton,
53
67
  returnHomeButtonLabel: alreadyLoggedInConfig.returnHomeButtonLabel,
54
68
  returnHomePath: alreadyLoggedInConfig.returnHomePath,
69
+ signInPath,
70
+ signInLabel,
55
71
  };
56
72
  }
57
73
 
@@ -3,6 +3,9 @@
3
3
  import type { HazoConnectAdapter } from "hazo_connect";
4
4
  import { createCrudService } from "hazo_connect/server";
5
5
  import argon2 from "argon2";
6
+ import { create_app_logger } from "../app_logger";
7
+ import { sanitize_error_for_user } from "../utils/error_sanitizer";
8
+ import { get_filename, get_line_number } from "../utils/api_route_helpers";
6
9
 
7
10
  // section: types
8
11
  export type LoginData = {
@@ -15,6 +18,7 @@ export type LoginResult = {
15
18
  user_id?: string;
16
19
  error?: string;
17
20
  email_not_verified?: boolean;
21
+ stored_url_on_logon?: string | null;
18
22
  };
19
23
 
20
24
  // section: helpers
@@ -98,20 +102,32 @@ export async function authenticate_user(
98
102
  last_logon: now,
99
103
  login_attempts: 0,
100
104
  changed_at: now,
105
+ url_on_logon: null, // Clear the stored redirect URL after successful login
101
106
  }
102
107
  );
103
108
 
104
109
  return {
105
110
  success: true,
106
111
  user_id: user.id as string,
112
+ stored_url_on_logon: user.url_on_logon as string | null | undefined,
107
113
  };
108
114
  } catch (error) {
109
- const error_message =
110
- error instanceof Error ? error.message : "Unknown error";
115
+ const logger = create_app_logger();
116
+ const user_friendly_error = sanitize_error_for_user(error, {
117
+ logToConsole: true,
118
+ logToLogger: true,
119
+ logger,
120
+ context: {
121
+ filename: "login_service.ts",
122
+ line_number: get_line_number(),
123
+ email: data.email,
124
+ operation: "authenticate_user",
125
+ },
126
+ });
111
127
 
112
128
  return {
113
129
  success: false,
114
- error: error_message,
130
+ error: user_friendly_error,
115
131
  };
116
132
  }
117
133
  }
@@ -10,12 +10,15 @@ import { get_profile_picture_config } from "../profile_picture_config.server";
10
10
  import { map_ui_source_to_db } from "./profile_picture_source_mapper";
11
11
  import { create_app_logger } from "../app_logger";
12
12
  import { send_template_email } from "./email_service";
13
+ import { sanitize_error_for_user } from "../utils/error_sanitizer";
14
+ import { get_filename, get_line_number } from "../utils/api_route_helpers";
13
15
 
14
16
  // section: types
15
17
  export type RegistrationData = {
16
18
  email: string;
17
19
  password: string;
18
20
  name?: string;
21
+ url_on_logon?: string;
19
22
  };
20
23
 
21
24
  export type RegistrationResult = {
@@ -36,7 +39,7 @@ export async function register_user(
36
39
  data: RegistrationData,
37
40
  ): Promise<RegistrationResult> {
38
41
  try {
39
- const { email, password, name } = data;
42
+ const { email, password, name, url_on_logon } = data;
40
43
 
41
44
  // Create CRUD service for hazo_users table
42
45
  const users_service = createCrudService(adapter, "hazo_users");
@@ -77,6 +80,14 @@ export async function register_user(
77
80
  insert_data.name = name;
78
81
  }
79
82
 
83
+ // Validate and include url_on_logon if provided
84
+ if (url_on_logon) {
85
+ // Ensure it's a relative path starting with / but not //
86
+ if (url_on_logon.startsWith("/") && !url_on_logon.startsWith("//")) {
87
+ insert_data.url_on_logon = url_on_logon;
88
+ }
89
+ }
90
+
80
91
  // Set default profile picture if enabled
81
92
  const profile_picture_config = get_profile_picture_config();
82
93
  if (profile_picture_config.user_photo_default) {
@@ -151,12 +162,22 @@ export async function register_user(
151
162
  user_id,
152
163
  };
153
164
  } catch (error) {
154
- const error_message =
155
- error instanceof Error ? error.message : "Unknown error";
165
+ const logger = create_app_logger();
166
+ const user_friendly_error = sanitize_error_for_user(error, {
167
+ logToConsole: true,
168
+ logToLogger: true,
169
+ logger,
170
+ context: {
171
+ filename: "registration_service.ts",
172
+ line_number: get_line_number(),
173
+ email: data.email,
174
+ operation: "register_user",
175
+ },
176
+ });
156
177
 
157
178
  return {
158
179
  success: false,
159
- error: error_message,
180
+ error: user_friendly_error,
160
181
  };
161
182
  }
162
183
  }
@@ -3,6 +3,9 @@
3
3
  import type { HazoConnectAdapter } from "hazo_connect";
4
4
  import { createCrudService } from "hazo_connect/server";
5
5
  import { map_ui_source_to_db, type ProfilePictureSourceUI } from "./profile_picture_source_mapper";
6
+ import { create_app_logger } from "../app_logger";
7
+ import { sanitize_error_for_user } from "../utils/error_sanitizer";
8
+ import { get_filename, get_line_number } from "../utils/api_route_helpers";
6
9
 
7
10
  // section: types
8
11
  export type UserUpdateData = {
@@ -116,12 +119,22 @@ export async function update_user_profile(
116
119
  email_changed,
117
120
  };
118
121
  } catch (error) {
119
- const error_message =
120
- error instanceof Error ? error.message : "Unknown error";
122
+ const logger = create_app_logger();
123
+ const user_friendly_error = sanitize_error_for_user(error, {
124
+ logToConsole: true,
125
+ logToLogger: true,
126
+ logger,
127
+ context: {
128
+ filename: "user_update_service.ts",
129
+ line_number: get_line_number(),
130
+ user_id,
131
+ operation: "update_user_profile",
132
+ },
133
+ });
121
134
 
122
135
  return {
123
136
  success: false,
124
- error: error_message,
137
+ error: user_friendly_error,
125
138
  };
126
139
  }
127
140
  }
@@ -0,0 +1,73 @@
1
+ // file_description: load ui shell layout settings 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 UiShellLayoutMode = "test_sidebar" | "standalone";
7
+
8
+ export type UiShellConfig = {
9
+ layout_mode: UiShellLayoutMode;
10
+ standalone_heading: string;
11
+ standalone_description: string;
12
+ standalone_wrapper_class: string;
13
+ standalone_content_class: string;
14
+ standalone_show_heading: boolean;
15
+ standalone_show_description: boolean;
16
+ };
17
+
18
+ // section: helpers
19
+ /**
20
+ * Reads ui shell configuration controlling whether pages use the sidebar test shell
21
+ * or a clean standalone wrapper that inherits consumer project styling.
22
+ */
23
+ export function get_ui_shell_config(): UiShellConfig {
24
+ const section = "hazo_auth__ui_shell";
25
+
26
+ const layoutModeValue = get_config_value(section, "layout_mode", "test_sidebar").toLowerCase();
27
+ const layout_mode: UiShellLayoutMode =
28
+ layoutModeValue === "standalone" ? "standalone" : "test_sidebar";
29
+
30
+ const standalone_heading = get_config_value(
31
+ section,
32
+ "standalone_heading",
33
+ "Welcome to hazo auth"
34
+ );
35
+ const standalone_description = get_config_value(
36
+ section,
37
+ "standalone_description",
38
+ "Reuse the packaged authentication flows while inheriting your existing app shell styles."
39
+ );
40
+ const standalone_wrapper_class = get_config_value(
41
+ section,
42
+ "standalone_wrapper_class",
43
+ "cls_standalone_shell flex min-h-screen w-full items-center justify-center bg-background px-4 py-10"
44
+ );
45
+ const standalone_content_class = get_config_value(
46
+ section,
47
+ "standalone_content_class",
48
+ "cls_standalone_shell_content w-full max-w-5xl shadow-xl rounded-2xl border bg-card"
49
+ );
50
+ const standalone_show_heading = get_config_value(
51
+ section,
52
+ "standalone_show_heading",
53
+ "true"
54
+ ).toLowerCase() === "true";
55
+ const standalone_show_description = get_config_value(
56
+ section,
57
+ "standalone_show_description",
58
+ "true"
59
+ ).toLowerCase() === "true";
60
+
61
+ return {
62
+ layout_mode,
63
+ standalone_heading,
64
+ standalone_description,
65
+ standalone_wrapper_class,
66
+ standalone_content_class,
67
+ standalone_show_heading,
68
+ standalone_show_description,
69
+ };
70
+ }
71
+
72
+
73
+
@@ -0,0 +1,75 @@
1
+ // file_description: utility functions for sanitizing error messages for user display
2
+ // section: imports
3
+ import { create_app_logger } from "../app_logger";
4
+
5
+ // section: constants
6
+ const USER_FRIENDLY_ERROR_MESSAGE = "We are facing some issues in our system, please try again later.";
7
+
8
+ // section: types
9
+ export type ErrorSanitizationOptions = {
10
+ logToConsole?: boolean;
11
+ logToLogger?: boolean;
12
+ logger?: ReturnType<typeof create_app_logger>;
13
+ context?: Record<string, unknown>;
14
+ };
15
+
16
+ // section: helpers
17
+ /**
18
+ * Sanitizes error messages for user display
19
+ * Replaces technical error messages with user-friendly ones
20
+ * @param error - The error object or message
21
+ * @param options - Options for logging and context
22
+ * @returns User-friendly error message
23
+ */
24
+ export function sanitize_error_for_user(
25
+ error: unknown,
26
+ options: ErrorSanitizationOptions = {}
27
+ ): string {
28
+ const { logToConsole = true, logToLogger = true, logger, context = {} } = options;
29
+
30
+ // Extract detailed error message
31
+ const detailed_error_message =
32
+ error instanceof Error ? error.message : String(error);
33
+ const error_stack = error instanceof Error ? error.stack : undefined;
34
+
35
+ // Log detailed error to console
36
+ if (logToConsole) {
37
+ console.error("Detailed error:", {
38
+ message: detailed_error_message,
39
+ stack: error_stack,
40
+ ...context,
41
+ });
42
+ }
43
+
44
+ // Log detailed error to logger if provided
45
+ if (logToLogger && logger) {
46
+ logger.error("error_occurred", {
47
+ filename: context.filename as string || "unknown",
48
+ line_number: context.line_number as number || 0,
49
+ error_message: detailed_error_message,
50
+ error_stack,
51
+ ...context,
52
+ });
53
+ }
54
+
55
+ // Check if error is a PostgREST or database-related error
56
+ const is_database_error =
57
+ detailed_error_message.includes("PostgREST") ||
58
+ detailed_error_message.includes("403 Forbidden") ||
59
+ detailed_error_message.includes("404 Not Found") ||
60
+ detailed_error_message.includes("500 Internal Server Error") ||
61
+ detailed_error_message.includes("database") ||
62
+ detailed_error_message.includes("connection") ||
63
+ detailed_error_message.includes("timeout");
64
+
65
+ // Return user-friendly message for database/API errors
66
+ if (is_database_error) {
67
+ return USER_FRIENDLY_ERROR_MESSAGE;
68
+ }
69
+
70
+ // For other errors, return the original message (could be user-friendly already)
71
+ // But still log the detailed error
72
+ return detailed_error_message;
73
+ }
74
+
75
+
@@ -1,8 +1,8 @@
1
1
  // file_description: showcase the email_verification_layout component within storybook for review and testing
2
2
  // section: imports
3
3
  import type { Meta, StoryObj } from "@storybook/react";
4
- import EmailVerificationLayout from "@/components/layouts/email_verification";
5
- import { createLayoutDataClient } from "@/components/layouts/shared/data/layout_data_client";
4
+ import EmailVerificationLayout from "../components/layouts/email_verification";
5
+ import { createLayoutDataClient } from "../components/layouts/shared/data/layout_data_client";
6
6
 
7
7
  // section: metadata
8
8
  const meta: Meta<typeof EmailVerificationLayout> = {
@@ -1,8 +1,8 @@
1
1
  // file_description: showcase the forgot_password_layout component within storybook for review and testing
2
2
  // section: imports
3
3
  import type { Meta, StoryObj } from "@storybook/react";
4
- import ForgotPasswordLayout from "@/components/layouts/forgot_password";
5
- import { createLayoutDataClient } from "@/components/layouts/shared/data/layout_data_client";
4
+ import ForgotPasswordLayout from "../components/layouts/forgot_password";
5
+ import { createLayoutDataClient } from "../components/layouts/shared/data/layout_data_client";
6
6
 
7
7
  // section: metadata
8
8
  const meta: Meta<typeof ForgotPasswordLayout> = {
@@ -1,8 +1,8 @@
1
1
  // file_description: showcase the login_layout component within storybook for review and testing
2
2
  // section: imports
3
3
  import type { Meta, StoryObj } from "@storybook/react";
4
- import LoginLayout from "@/components/layouts/login";
5
- import { createLayoutDataClient } from "@/components/layouts/shared/data/layout_data_client";
4
+ import LoginLayout from "../components/layouts/login";
5
+ import { createLayoutDataClient } from "../components/layouts/shared/data/layout_data_client";
6
6
 
7
7
  // section: metadata
8
8
  const meta: Meta<typeof LoginLayout> = {
@@ -1,8 +1,8 @@
1
1
  // file_description: showcase the register_layout component within storybook for review and testing
2
2
  // section: imports
3
3
  import type { Meta, StoryObj } from "@storybook/react";
4
- import RegisterLayout from "@/components/layouts/register";
5
- import { createLayoutDataClient } from "@/components/layouts/shared/data/layout_data_client";
4
+ import RegisterLayout from "../components/layouts/register";
5
+ import { createLayoutDataClient } from "../components/layouts/shared/data/layout_data_client";
6
6
 
7
7
  // section: metadata
8
8
  const meta: Meta<typeof RegisterLayout> = {
package/tsconfig.json CHANGED
@@ -17,10 +17,7 @@
17
17
  {
18
18
  "name": "next"
19
19
  }
20
- ],
21
- "paths": {
22
- "@/*": ["./src/*"]
23
- }
20
+ ]
24
21
  },
25
22
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
26
23
  "exclude": ["node_modules"]