hazo_auth 0.1.2 → 1.0.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 (89) hide show
  1. package/hazo_auth_config.example.ini +75 -0
  2. package/instrumentation.ts +1 -1
  3. package/next.config.mjs +1 -1
  4. package/package.json +4 -1
  5. package/src/app/api/{auth → hazo_auth/auth}/upload_profile_picture/route.ts +2 -2
  6. package/src/app/api/{auth → hazo_auth}/change_password/route.ts +23 -0
  7. package/src/app/api/hazo_auth/get_auth/route.ts +89 -0
  8. package/src/app/api/hazo_auth/invalidate_cache/route.ts +139 -0
  9. package/src/app/api/{auth → hazo_auth}/library_photos/route.ts +3 -0
  10. package/src/app/api/{auth → hazo_auth}/logout/route.ts +27 -0
  11. package/src/app/api/hazo_auth/upload_profile_picture/route.ts +268 -0
  12. package/src/app/api/hazo_auth/user_management/permissions/route.ts +367 -0
  13. package/src/app/api/hazo_auth/user_management/roles/route.ts +442 -0
  14. package/src/app/api/hazo_auth/user_management/users/roles/route.ts +367 -0
  15. package/src/app/api/hazo_auth/user_management/users/route.ts +239 -0
  16. package/src/app/api/{auth → hazo_auth}/validate_reset_token/route.ts +3 -0
  17. package/src/app/api/{auth → hazo_auth}/verify_email/route.ts +3 -0
  18. package/src/app/globals.css +1 -1
  19. package/src/app/hazo_auth/user_management/page.tsx +14 -0
  20. package/src/app/hazo_auth/user_management/user_management_page_client.tsx +16 -0
  21. package/src/app/hazo_connect/api/sqlite/data/route.ts +7 -1
  22. package/src/app/hazo_connect/api/sqlite/schema/route.ts +14 -4
  23. package/src/app/hazo_connect/api/sqlite/tables/route.ts +14 -4
  24. package/src/app/hazo_connect/sqlite_admin/sqlite-admin-client.tsx +40 -3
  25. package/src/app/layout.tsx +1 -1
  26. package/src/app/page.tsx +4 -4
  27. package/src/components/layouts/email_verification/hooks/use_email_verification.ts +4 -4
  28. package/src/components/layouts/email_verification/index.tsx +1 -1
  29. package/src/components/layouts/forgot_password/hooks/use_forgot_password_form.ts +1 -1
  30. package/src/components/layouts/login/hooks/use_login_form.ts +2 -2
  31. package/src/components/layouts/my_settings/components/profile_picture_dialog.tsx +1 -1
  32. package/src/components/layouts/my_settings/components/profile_picture_library_tab.tsx +35 -6
  33. package/src/components/layouts/my_settings/hooks/use_my_settings.ts +5 -5
  34. package/src/components/layouts/my_settings/index.tsx +1 -1
  35. package/src/components/layouts/register/hooks/use_register_form.ts +1 -1
  36. package/src/components/layouts/reset_password/hooks/use_reset_password_form.ts +3 -3
  37. package/src/components/layouts/reset_password/index.tsx +2 -2
  38. package/src/components/layouts/shared/components/logout_button.tsx +1 -1
  39. package/src/components/layouts/shared/components/profile_pic_menu.tsx +321 -0
  40. package/src/components/layouts/shared/components/profile_pic_menu_wrapper.tsx +40 -0
  41. package/src/components/layouts/shared/components/sidebar_layout_wrapper.tsx +22 -72
  42. package/src/components/layouts/shared/components/unauthorized_guard.tsx +1 -1
  43. package/src/components/layouts/shared/hooks/use_auth_status.ts +1 -1
  44. package/src/components/layouts/shared/hooks/use_hazo_auth.ts +158 -0
  45. package/src/components/layouts/user_management/components/roles_matrix.tsx +607 -0
  46. package/src/components/layouts/user_management/index.tsx +1295 -0
  47. package/src/components/ui/alert-dialog.tsx +141 -0
  48. package/src/components/ui/checkbox.tsx +30 -0
  49. package/src/components/ui/dropdown-menu.tsx +201 -0
  50. package/src/components/ui/table.tsx +120 -0
  51. package/src/lib/auth/auth_cache.ts +220 -0
  52. package/src/lib/auth/auth_rate_limiter.ts +121 -0
  53. package/src/lib/auth/auth_types.ts +65 -0
  54. package/src/lib/auth/hazo_get_auth.server.ts +333 -0
  55. package/src/lib/auth_utility_config.server.ts +136 -0
  56. package/src/lib/hazo_connect_setup.server.ts +2 -3
  57. package/src/lib/my_settings_config.server.ts +1 -1
  58. package/src/lib/profile_pic_menu_config.server.ts +138 -0
  59. package/src/lib/reset_password_config.server.ts +5 -5
  60. package/src/lib/services/email_service.ts +2 -2
  61. package/src/lib/services/profile_picture_remove_service.ts +1 -1
  62. package/src/lib/services/token_service.ts +2 -2
  63. package/src/lib/user_management_config.server.ts +40 -0
  64. package/src/lib/utils.ts +1 -1
  65. package/src/middleware.ts +15 -13
  66. package/src/server/types/express.d.ts +1 -0
  67. package/src/stories/project_overview.stories.tsx +1 -1
  68. package/tailwind.config.ts +1 -1
  69. /package/src/app/api/{auth → hazo_auth}/forgot_password/route.ts +0 -0
  70. /package/src/app/api/{auth → hazo_auth}/login/route.ts +0 -0
  71. /package/src/app/api/{auth → hazo_auth}/me/route.ts +0 -0
  72. /package/src/app/api/{auth → hazo_auth}/profile_picture/[filename]/route.ts +0 -0
  73. /package/src/app/api/{auth → hazo_auth}/register/route.ts +0 -0
  74. /package/src/app/api/{auth → hazo_auth}/remove_profile_picture/route.ts +0 -0
  75. /package/src/app/api/{auth → hazo_auth}/resend_verification/route.ts +0 -0
  76. /package/src/app/api/{auth → hazo_auth}/reset_password/route.ts +0 -0
  77. /package/src/app/api/{auth → hazo_auth}/update_user/route.ts +0 -0
  78. /package/src/app/{forgot_password → hazo_auth/forgot_password}/forgot_password_page_client.tsx +0 -0
  79. /package/src/app/{forgot_password → hazo_auth/forgot_password}/page.tsx +0 -0
  80. /package/src/app/{login → hazo_auth/login}/login_page_client.tsx +0 -0
  81. /package/src/app/{login → hazo_auth/login}/page.tsx +0 -0
  82. /package/src/app/{my_settings → hazo_auth/my_settings}/my_settings_page_client.tsx +0 -0
  83. /package/src/app/{my_settings → hazo_auth/my_settings}/page.tsx +0 -0
  84. /package/src/app/{register → hazo_auth/register}/page.tsx +0 -0
  85. /package/src/app/{register → hazo_auth/register}/register_page_client.tsx +0 -0
  86. /package/src/app/{reset_password → hazo_auth/reset_password}/page.tsx +0 -0
  87. /package/src/app/{reset_password → hazo_auth/reset_password}/reset_password_page_client.tsx +0 -0
  88. /package/src/app/{verify_email → hazo_auth/verify_email}/page.tsx +0 -0
  89. /package/src/app/{verify_email → hazo_auth/verify_email}/verify_email_page_client.tsx +0 -0
@@ -251,6 +251,81 @@ enable_admin_ui = true
251
251
  # Login path (redirect target in unauthorized message)
252
252
  # login_path = /login
253
253
 
254
+ [hazo_auth__user_management]
255
+ # User Management configuration
256
+ # Application permission list defaults (comma-separated)
257
+ # These permissions will be shown in the Permissions tab and can be migrated to the database
258
+ # Example: application_permission_list_defaults = PERM_ONE,PERM_TWO,PERM_THREE
259
+ # application_permission_list_defaults =
260
+
261
+ [hazo_auth__auth_utility]
262
+ # Authentication utility configuration
263
+
264
+ # Cache settings
265
+ # Maximum number of users to cache (LRU eviction, default: 10000)
266
+ # cache_max_users = 10000
267
+
268
+ # Cache TTL in minutes (default: 15)
269
+ # cache_ttl_minutes = 15
270
+
271
+ # Force cache refresh if older than this many minutes (default: 30)
272
+ # cache_max_age_minutes = 30
273
+
274
+ # Rate limiting for /api/auth/get_auth endpoint
275
+ # Per-user rate limit (requests per minute, default: 100)
276
+ # rate_limit_per_user = 100
277
+
278
+ # Per-IP rate limit for unauthenticated requests (default: 200)
279
+ # rate_limit_per_ip = 200
280
+
281
+ # Permission check behavior
282
+ # Log all permission denials for security audit (default: true)
283
+ # log_permission_denials = true
284
+
285
+ # User-friendly error messages
286
+ # Enable mapping of technical permissions to user-friendly messages (default: true)
287
+ # enable_friendly_error_messages = true
288
+
289
+ # Permission message mappings (optional, comma-separated: permission_name:user_message)
290
+ # Example: admin_user_management:You don't have access to user management,admin_role_management:You don't have access to role management
291
+ # permission_error_messages =
292
+
293
+ [hazo_auth__profile_pic_menu]
294
+ # Profile picture menu configuration
295
+ # This component can be used in navbar or sidebar to show user profile picture or sign up/sign in buttons
296
+
297
+ # Button configuration for unauthenticated users
298
+ # Show only "Sign Up" button when true, show both "Sign Up" and "Sign In" buttons when false (default)
299
+ # show_single_button = false
300
+
301
+ # Sign up button label
302
+ # sign_up_label = Sign Up
303
+
304
+ # Sign in button label
305
+ # sign_in_label = Sign In
306
+
307
+ # Register page path
308
+ # register_path = /register
309
+
310
+ # Login page path
311
+ # login_path = /login
312
+
313
+ # Settings page path (shown in dropdown menu when authenticated)
314
+ # settings_path = /my_settings
315
+
316
+ # Logout API endpoint path
317
+ # logout_path = /api/auth/logout
318
+
319
+ # Custom menu items (optional)
320
+ # Format: "type:label:value_or_href:order" for info/link, or "separator:order" for separator
321
+ # Examples:
322
+ # - Info item: "info:Phone:+1234567890:3"
323
+ # - Link item: "link:My Account:/account:4"
324
+ # - Separator: "separator:2"
325
+ # Custom items are added to the default menu items (name, email, separator, Settings, Logout)
326
+ # Items are sorted by type (info first, then separators, then links) and then by order within each type
327
+ # custom_menu_items =
328
+
254
329
  [hazo_auth__profile_picture]
255
330
  # Profile picture configuration
256
331
  # This configuration is used by:
@@ -9,7 +9,7 @@ export async function register() {
9
9
  const hazo_notify_module = await import("hazo_notify");
10
10
 
11
11
  // Step 2: Load hazo_notify emailer configuration
12
- // This reads from hazo_notify_config.ini in the ui_component directory (same location as hazo_auth_config.ini)
12
+ // This reads from hazo_notify_config.ini in the project root (same location as hazo_auth_config.ini)
13
13
  const { load_emailer_config } = hazo_notify_module;
14
14
  const notify_config = load_emailer_config();
15
15
 
package/next.config.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // file_description: configure next.js application settings for the ui_component project
1
+ // file_description: configure next.js application settings for the hazo_auth project
2
2
  // section: imports
3
3
  import path from "path";
4
4
  import { fileURLToPath } from "url";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hazo_auth",
3
- "version": "0.1.2",
3
+ "version": "1.0.0",
4
4
  "files": [
5
5
  "src/**/*",
6
6
  "public/file.svg",
@@ -35,8 +35,11 @@
35
35
  "test:watch": "cross-env NODE_ENV=test POSTGREST_URL=http://209.38.26.241:4402 POSTGREST_API_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYXBpX3VzZXIifQ.zBoUGymrxTUk1DNYIGUCtQU4HFaWEHlbE9_8Y3hUaTw jest --watch"
36
36
  },
37
37
  "dependencies": {
38
+ "@radix-ui/react-alert-dialog": "^1.1.15",
38
39
  "@radix-ui/react-avatar": "^1.1.11",
40
+ "@radix-ui/react-checkbox": "^1.3.3",
39
41
  "@radix-ui/react-dialog": "^1.1.15",
42
+ "@radix-ui/react-dropdown-menu": "^2.1.16",
40
43
  "@radix-ui/react-label": "^2.1.8",
41
44
  "@radix-ui/react-separator": "^1.1.8",
42
45
  "@radix-ui/react-slot": "^1.2.4",
@@ -160,7 +160,7 @@ export async function POST(request: NextRequest) {
160
160
  // Generate URL (relative to public or absolute)
161
161
  // For Next.js, we'll serve from a public route or use absolute path
162
162
  // For now, use a relative path that can be served via API or static file serving
163
- const profilePictureUrl = `/api/auth/profile_picture/${fileName}`;
163
+ const profilePictureUrl = `/api/hazo_auth/profile_picture/${fileName}`;
164
164
 
165
165
  // Update user record
166
166
  const updateResult = await update_user_profile_picture(
@@ -198,7 +198,7 @@ export async function POST(request: NextRequest) {
198
198
  // Only delete if the old profile picture was an uploaded file
199
199
  if (oldSourceUI === "upload") {
200
200
  try {
201
- // Extract filename from URL (e.g., /api/auth/profile_picture/user_id.jpg)
201
+ // Extract filename from URL (e.g., /api/hazo_auth/profile_picture/user_id.jpg)
202
202
  const oldFileName = oldProfilePictureUrl.split("/").pop();
203
203
 
204
204
  if (oldFileName) {
@@ -6,6 +6,8 @@ import { create_app_logger } from "@/lib/app_logger";
6
6
  import { change_password } from "@/lib/services/password_change_service";
7
7
  import { get_filename, get_line_number } from "@/lib/utils/api_route_helpers";
8
8
  import { require_auth } from "@/lib/auth/auth_utils.server";
9
+ import { get_auth_cache } from "@/lib/auth/auth_cache";
10
+ import { get_auth_utility_config } from "@/lib/auth_utility_config.server";
9
11
 
10
12
  // section: api_handler
11
13
  export async function POST(request: NextRequest) {
@@ -75,6 +77,27 @@ export async function POST(request: NextRequest) {
75
77
  );
76
78
  }
77
79
 
80
+ // Invalidate user cache after password change
81
+ try {
82
+ const config = get_auth_utility_config();
83
+ const cache = get_auth_cache(
84
+ config.cache_max_users,
85
+ config.cache_ttl_minutes,
86
+ config.cache_max_age_minutes,
87
+ );
88
+ cache.invalidate_user(user_id);
89
+ } catch (cache_error) {
90
+ // Log but don't fail password change if cache invalidation fails
91
+ const cache_error_message =
92
+ cache_error instanceof Error ? cache_error.message : "Unknown error";
93
+ logger.warn("password_change_cache_invalidation_failed", {
94
+ filename: get_filename(),
95
+ line_number: get_line_number(),
96
+ user_id,
97
+ error: cache_error_message,
98
+ });
99
+ }
100
+
78
101
  logger.info("password_change_successful", {
79
102
  filename: get_filename(),
80
103
  line_number: get_line_number(),
@@ -0,0 +1,89 @@
1
+ // file_description: API route for hazo_get_auth utility (client-side calls)
2
+ // section: imports
3
+ import { NextRequest, NextResponse } from "next/server";
4
+ import { hazo_get_auth } from "@/lib/auth/hazo_get_auth.server";
5
+ import { PermissionError } from "@/lib/auth/auth_types";
6
+ import { create_app_logger } from "@/lib/app_logger";
7
+ import { get_filename, get_line_number } from "@/lib/utils/api_route_helpers";
8
+
9
+ // section: route_config
10
+ export const dynamic = "force-dynamic";
11
+
12
+ // section: api_handler
13
+ /**
14
+ * POST - Get authentication status and permissions
15
+ * Body: { required_permissions?: string[], strict?: boolean }
16
+ */
17
+ export async function POST(request: NextRequest) {
18
+ const logger = create_app_logger();
19
+
20
+ try {
21
+ const body = await request.json();
22
+ const { required_permissions, strict } = body;
23
+
24
+ // Validate required_permissions if provided
25
+ if (
26
+ required_permissions !== undefined &&
27
+ (!Array.isArray(required_permissions) ||
28
+ !required_permissions.every((p) => typeof p === "string"))
29
+ ) {
30
+ return NextResponse.json(
31
+ { error: "required_permissions must be an array of strings" },
32
+ { status: 400 },
33
+ );
34
+ }
35
+
36
+ // Validate strict if provided
37
+ if (strict !== undefined && typeof strict !== "boolean") {
38
+ return NextResponse.json(
39
+ { error: "strict must be a boolean" },
40
+ { status: 400 },
41
+ );
42
+ }
43
+
44
+ // Call hazo_get_auth
45
+ const result = await hazo_get_auth(request, {
46
+ required_permissions,
47
+ strict,
48
+ });
49
+
50
+ return NextResponse.json(result, { status: 200 });
51
+ } catch (error) {
52
+ // Handle PermissionError (strict mode)
53
+ if (error instanceof PermissionError) {
54
+ logger.warn("auth_utility_permission_error", {
55
+ filename: get_filename(),
56
+ line_number: get_line_number(),
57
+ missing_permissions: error.missing_permissions,
58
+ required_permissions: error.required_permissions,
59
+ });
60
+
61
+ return NextResponse.json(
62
+ {
63
+ error: "Permission denied",
64
+ missing_permissions: error.missing_permissions,
65
+ user_friendly_message: error.user_friendly_message,
66
+ },
67
+ { status: 403 },
68
+ );
69
+ }
70
+
71
+ // Handle other errors
72
+ const error_message =
73
+ error instanceof Error ? error.message : "Unknown error";
74
+ const error_stack = error instanceof Error ? error.stack : undefined;
75
+
76
+ logger.error("auth_utility_api_error", {
77
+ filename: get_filename(),
78
+ line_number: get_line_number(),
79
+ error_message,
80
+ error_stack,
81
+ });
82
+
83
+ return NextResponse.json(
84
+ { error: error_message },
85
+ { status: 500 },
86
+ );
87
+ }
88
+ }
89
+
@@ -0,0 +1,139 @@
1
+ // file_description: API route for manual cache invalidation (admin endpoint)
2
+ // section: imports
3
+ import { NextRequest, NextResponse } from "next/server";
4
+ import { get_auth_cache } from "@/lib/auth/auth_cache";
5
+ import { get_auth_utility_config } from "@/lib/auth_utility_config.server";
6
+ import { create_app_logger } from "@/lib/app_logger";
7
+ import { get_filename, get_line_number } from "@/lib/utils/api_route_helpers";
8
+ import { hazo_get_auth } from "@/lib/auth/hazo_get_auth.server";
9
+
10
+ // section: route_config
11
+ export const dynamic = "force-dynamic";
12
+
13
+ // section: api_handler
14
+ /**
15
+ * POST - Manually invalidate auth cache
16
+ * Body: { user_id?: string, role_ids?: number[], invalidate_all?: boolean }
17
+ * Requires admin permission (checked via hazo_get_auth)
18
+ */
19
+ export async function POST(request: NextRequest) {
20
+ const logger = create_app_logger();
21
+
22
+ try {
23
+ // Check authentication and admin permission
24
+ const auth_result = await hazo_get_auth(request, {
25
+ required_permissions: ["admin_user_management"], // Require admin permission
26
+ strict: true, // Throw error if not authorized
27
+ });
28
+
29
+ if (!auth_result.authenticated) {
30
+ return NextResponse.json(
31
+ { error: "Authentication required" },
32
+ { status: 401 },
33
+ );
34
+ }
35
+
36
+ const body = await request.json();
37
+ const { user_id, role_ids, invalidate_all } = body;
38
+
39
+ // Validate input
40
+ if (invalidate_all !== undefined && typeof invalidate_all !== "boolean") {
41
+ return NextResponse.json(
42
+ { error: "invalidate_all must be a boolean" },
43
+ { status: 400 },
44
+ );
45
+ }
46
+
47
+ if (user_id !== undefined && typeof user_id !== "string") {
48
+ return NextResponse.json(
49
+ { error: "user_id must be a string" },
50
+ { status: 400 },
51
+ );
52
+ }
53
+
54
+ if (
55
+ role_ids !== undefined &&
56
+ (!Array.isArray(role_ids) ||
57
+ !role_ids.every((id) => typeof id === "number"))
58
+ ) {
59
+ return NextResponse.json(
60
+ { error: "role_ids must be an array of numbers" },
61
+ { status: 400 },
62
+ );
63
+ }
64
+
65
+ const config = get_auth_utility_config();
66
+ const cache = get_auth_cache(
67
+ config.cache_max_users,
68
+ config.cache_ttl_minutes,
69
+ config.cache_max_age_minutes,
70
+ );
71
+
72
+ // Perform invalidation
73
+ if (invalidate_all === true) {
74
+ cache.invalidate_all();
75
+ logger.info("auth_cache_invalidated_all", {
76
+ filename: get_filename(),
77
+ line_number: get_line_number(),
78
+ user_id: auth_result.user.id,
79
+ });
80
+ } else if (user_id) {
81
+ cache.invalidate_user(user_id);
82
+ logger.info("auth_cache_invalidated_user", {
83
+ filename: get_filename(),
84
+ line_number: get_line_number(),
85
+ invalidated_user_id: user_id,
86
+ admin_user_id: auth_result.user.id,
87
+ });
88
+ } else if (role_ids && role_ids.length > 0) {
89
+ cache.invalidate_by_roles(role_ids);
90
+ logger.info("auth_cache_invalidated_roles", {
91
+ filename: get_filename(),
92
+ line_number: get_line_number(),
93
+ role_ids,
94
+ admin_user_id: auth_result.user.id,
95
+ });
96
+ } else {
97
+ return NextResponse.json(
98
+ {
99
+ error:
100
+ "Must provide user_id, role_ids, or invalidate_all=true",
101
+ },
102
+ { status: 400 },
103
+ );
104
+ }
105
+
106
+ return NextResponse.json(
107
+ {
108
+ success: true,
109
+ message: "Cache invalidated successfully",
110
+ },
111
+ { status: 200 },
112
+ );
113
+ } catch (error) {
114
+ // Handle PermissionError (strict mode)
115
+ if (error instanceof Error && error.name === "PermissionError") {
116
+ return NextResponse.json(
117
+ { error: "Permission denied. Admin access required." },
118
+ { status: 403 },
119
+ );
120
+ }
121
+
122
+ const error_message =
123
+ error instanceof Error ? error.message : "Unknown error";
124
+ const error_stack = error instanceof Error ? error.stack : undefined;
125
+
126
+ logger.error("auth_cache_invalidation_error", {
127
+ filename: get_filename(),
128
+ line_number: get_line_number(),
129
+ error_message,
130
+ error_stack,
131
+ });
132
+
133
+ return NextResponse.json(
134
+ { error: "Failed to invalidate cache" },
135
+ { status: 500 },
136
+ );
137
+ }
138
+ }
139
+
@@ -5,6 +5,9 @@ import { get_library_categories, get_library_photos } from "@/lib/services/profi
5
5
  import { create_app_logger } from "@/lib/app_logger";
6
6
  import { get_filename, get_line_number } from "@/lib/utils/api_route_helpers";
7
7
 
8
+ // section: route_config
9
+ export const dynamic = 'force-dynamic';
10
+
8
11
  // section: api_handler
9
12
  export async function GET(request: NextRequest) {
10
13
  const logger = create_app_logger();
@@ -3,6 +3,8 @@
3
3
  import { NextRequest, NextResponse } from "next/server";
4
4
  import { create_app_logger } from "@/lib/app_logger";
5
5
  import { get_filename, get_line_number } from "@/lib/utils/api_route_helpers";
6
+ import { get_auth_cache } from "@/lib/auth/auth_cache";
7
+ import { get_auth_utility_config } from "@/lib/auth_utility_config.server";
6
8
 
7
9
  // section: api_handler
8
10
  export async function POST(request: NextRequest) {
@@ -32,6 +34,31 @@ export async function POST(request: NextRequest) {
32
34
  path: "/",
33
35
  });
34
36
 
37
+ // Invalidate user cache
38
+ if (user_id) {
39
+ try {
40
+ const config = get_auth_utility_config();
41
+ const cache = get_auth_cache(
42
+ config.cache_max_users,
43
+ config.cache_ttl_minutes,
44
+ config.cache_max_age_minutes,
45
+ );
46
+ cache.invalidate_user(user_id);
47
+ } catch (cache_error) {
48
+ // Log but don't fail logout if cache invalidation fails
49
+ const cache_error_message =
50
+ cache_error instanceof Error
51
+ ? cache_error.message
52
+ : "Unknown error";
53
+ logger.warn("logout_cache_invalidation_failed", {
54
+ filename: get_filename(),
55
+ line_number: get_line_number(),
56
+ user_id,
57
+ error: cache_error_message,
58
+ });
59
+ }
60
+ }
61
+
35
62
  if (user_email || user_id) {
36
63
  logger.info("logout_successful", {
37
64
  filename: get_filename(),