hazo_auth 10.32.2 → 10.33.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.
- package/cli-src/lib/auth/envelope_response.server.ts +56 -0
- package/cli-src/lib/auth/hazo_get_auth.server.ts +20 -6
- package/cli-src/lib/auth/with_auth.server.ts +15 -17
- package/cli-src/lib/auth/with_permission_issue_capture.server.ts +12 -40
- package/cli-src/lib/otp_config.server.ts +10 -1
- package/cli-src/lib/services/app_user_data_service.ts +19 -6
- package/dist/components/layouts/shared/components/profile_pic_menu.d.ts +22 -1
- package/dist/components/layouts/shared/components/profile_pic_menu.d.ts.map +1 -1
- package/dist/components/layouts/shared/components/profile_pic_menu.js +20 -19
- package/dist/components/layouts/shared/components/profile_pic_menu_wrapper.d.ts +5 -2
- package/dist/components/layouts/shared/components/profile_pic_menu_wrapper.d.ts.map +1 -1
- package/dist/components/layouts/shared/components/profile_pic_menu_wrapper.js +3 -3
- package/dist/lib/auth/envelope_response.server.d.ts +21 -0
- package/dist/lib/auth/envelope_response.server.d.ts.map +1 -0
- package/dist/lib/auth/envelope_response.server.js +32 -0
- package/dist/lib/auth/hazo_get_auth.server.d.ts.map +1 -1
- package/dist/lib/auth/hazo_get_auth.server.js +19 -6
- package/dist/lib/auth/with_auth.server.d.ts.map +1 -1
- package/dist/lib/auth/with_auth.server.js +9 -9
- package/dist/lib/auth/with_permission_issue_capture.server.d.ts.map +1 -1
- package/dist/lib/auth/with_permission_issue_capture.server.js +11 -28
- package/dist/lib/otp_config.server.d.ts.map +1 -1
- package/dist/lib/otp_config.server.js +6 -1
- package/dist/lib/services/app_user_data_service.d.ts.map +1 -1
- package/dist/lib/services/app_user_data_service.js +18 -6
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// file_description: builds a hazo_api-fail()-shaped JSON Response, using the real hazo_api.fail() when installed, otherwise a hand-built fallback matching the exact same envelope
|
|
2
|
+
// section: server_only_guard
|
|
3
|
+
import 'server-only';
|
|
4
|
+
|
|
5
|
+
// section: imports
|
|
6
|
+
import { optional_import } from 'hazo_core';
|
|
7
|
+
|
|
8
|
+
// section: envelope_response
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Builds an error Response in hazo_api's `fail()` envelope shape:
|
|
12
|
+
* `{ ok: false, error: { code, message, details? } }`.
|
|
13
|
+
*
|
|
14
|
+
* Uses the real `hazo_api.fail()` when hazo_auth's optional `hazo_api` peer
|
|
15
|
+
* is installed (richer HazoError enrichment, request-id/meta, etc.) —
|
|
16
|
+
* `optional_import`, not a literal `import('hazo_api')`, because a literal
|
|
17
|
+
* dynamic import of this optional peer breaks Turbopack builds (same
|
|
18
|
+
* reason `with_permission_issue_capture.server.ts`'s own `buildForbiddenResponse`
|
|
19
|
+
* already uses this pattern; this is that same helper generalized to any
|
|
20
|
+
* code/status/message, not just FORBIDDEN/403).
|
|
21
|
+
*
|
|
22
|
+
* Without hazo_api installed, hand-builds the identical top-level shape so
|
|
23
|
+
* a consumer's response parsing never has to care which path ran.
|
|
24
|
+
*/
|
|
25
|
+
export async function buildEnvelopeResponse(
|
|
26
|
+
code: string,
|
|
27
|
+
message: string,
|
|
28
|
+
opts: { status: number; details?: unknown },
|
|
29
|
+
): Promise<Response> {
|
|
30
|
+
const apiMod = await optional_import<{
|
|
31
|
+
fail?: (
|
|
32
|
+
code: string,
|
|
33
|
+
message: string,
|
|
34
|
+
opts?: { details?: unknown; status?: number },
|
|
35
|
+
) => Response;
|
|
36
|
+
}>('hazo_api');
|
|
37
|
+
|
|
38
|
+
if (apiMod?.fail) {
|
|
39
|
+
return apiMod.fail(code, message, {
|
|
40
|
+
status: opts.status,
|
|
41
|
+
...(opts.details !== undefined ? { details: opts.details } : {}),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return new Response(
|
|
46
|
+
JSON.stringify({
|
|
47
|
+
ok: false,
|
|
48
|
+
error: {
|
|
49
|
+
code,
|
|
50
|
+
message,
|
|
51
|
+
...(opts.details !== undefined ? { details: opts.details } : {}),
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
{ status: opts.status, headers: { 'Content-Type': 'application/json' } },
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -36,23 +36,37 @@ import { extract_scope_id_from_request } from "./scope_header.js";
|
|
|
36
36
|
// section: helpers
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
39
|
+
* Normalizes a `hazo_users.app_user_data` jsonb column value to a plain
|
|
40
|
+
* object, returning null on anything else.
|
|
41
|
+
*
|
|
42
|
+
* Most hazo_connect adapters (e.g. `PgAdapter`, built on postgres.js with
|
|
43
|
+
* its default type parsers) already hand back a parsed JS value for a
|
|
44
|
+
* jsonb column — never a JSON string. This used to only accept a string
|
|
45
|
+
* and `JSON.parse` it, which silently discarded every real object value
|
|
46
|
+
* (returning `null` even when data was genuinely set) instead of erroring
|
|
47
|
+
* loudly — see the identical fix/comment in app_user_data_service.ts's own
|
|
48
|
+
* copy of this helper. Still accepts a string for any adapter that
|
|
49
|
+
* genuinely returns jsonb as unparsed text.
|
|
50
|
+
* @param value - The raw `app_user_data` column value, parsed or not
|
|
41
51
|
* @returns Parsed object or null
|
|
42
52
|
*/
|
|
43
53
|
function parse_app_user_data(
|
|
44
|
-
|
|
54
|
+
value: unknown,
|
|
45
55
|
): Record<string, unknown> | null {
|
|
46
|
-
if (
|
|
56
|
+
if (value === null || value === undefined || value === "") {
|
|
47
57
|
return null;
|
|
48
58
|
}
|
|
49
59
|
|
|
50
|
-
if (typeof
|
|
60
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
61
|
+
return value as Record<string, unknown>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (typeof value !== "string") {
|
|
51
65
|
return null;
|
|
52
66
|
}
|
|
53
67
|
|
|
54
68
|
try {
|
|
55
|
-
const parsed = JSON.parse(
|
|
69
|
+
const parsed = JSON.parse(value);
|
|
56
70
|
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
57
71
|
return parsed as Record<string, unknown>;
|
|
58
72
|
}
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
getPermissionDeniedHandler,
|
|
22
22
|
type PermissionDeniedPayload,
|
|
23
23
|
} from "./with_permission_issue_capture.server.js";
|
|
24
|
+
import { buildEnvelopeResponse } from "./envelope_response.server.js";
|
|
24
25
|
import { get_app_permission_descriptions } from "../app_permissions_config.server.js";
|
|
25
26
|
|
|
26
27
|
// section: types
|
|
@@ -135,10 +136,9 @@ async function handle_auth_error(
|
|
|
135
136
|
request: Request,
|
|
136
137
|
): Promise<NextResponse> {
|
|
137
138
|
if (error instanceof HazoAuthError) {
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
);
|
|
139
|
+
return (await buildEnvelopeResponse(error.code, error.message, {
|
|
140
|
+
status: error.status_code,
|
|
141
|
+
})) as unknown as NextResponse;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
if (error instanceof PermissionError) {
|
|
@@ -157,10 +157,9 @@ async function handle_auth_error(
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
console.error("Unexpected error in route handler:", error);
|
|
160
|
-
return
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
);
|
|
160
|
+
return (await buildEnvelopeResponse("INTERNAL_ERROR", "Internal server error", {
|
|
161
|
+
status: 500,
|
|
162
|
+
})) as unknown as NextResponse;
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
/**
|
|
@@ -246,10 +245,11 @@ export function withAuth<TParams = Record<string, never>>(
|
|
|
246
245
|
const auth = await hazo_get_tenant_auth(request, options);
|
|
247
246
|
|
|
248
247
|
if (!auth.authenticated) {
|
|
249
|
-
return
|
|
250
|
-
|
|
248
|
+
return (await buildEnvelopeResponse(
|
|
249
|
+
"AUTHENTICATION_REQUIRED",
|
|
250
|
+
"Authentication required",
|
|
251
251
|
{ status: 401 },
|
|
252
|
-
);
|
|
252
|
+
)) as unknown as NextResponse;
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
// Check permissions if required_permissions were specified
|
|
@@ -270,13 +270,11 @@ export function withAuth<TParams = Record<string, never>>(
|
|
|
270
270
|
|
|
271
271
|
// Check tenant requirement
|
|
272
272
|
if (options.require_tenant && !auth.organization) {
|
|
273
|
-
return
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
code: "TENANT_REQUIRED",
|
|
277
|
-
},
|
|
273
|
+
return (await buildEnvelopeResponse(
|
|
274
|
+
"TENANT_REQUIRED",
|
|
275
|
+
"Organization context required",
|
|
278
276
|
{ status: 403 },
|
|
279
|
-
);
|
|
277
|
+
)) as unknown as NextResponse;
|
|
280
278
|
}
|
|
281
279
|
|
|
282
280
|
const params = await resolve_params(context);
|
|
@@ -4,9 +4,10 @@ import 'server-only';
|
|
|
4
4
|
|
|
5
5
|
// section: imports
|
|
6
6
|
import { type NextRequest } from 'next/server';
|
|
7
|
-
import { createLogger
|
|
7
|
+
import { createLogger } from 'hazo_core';
|
|
8
8
|
import { PermissionError } from './auth_types.js';
|
|
9
9
|
import { hazo_get_auth } from './hazo_get_auth.server.js';
|
|
10
|
+
import { buildEnvelopeResponse } from './envelope_response.server.js';
|
|
10
11
|
|
|
11
12
|
const log = createLogger('hazo_auth:permission_capture');
|
|
12
13
|
|
|
@@ -106,45 +107,16 @@ export function buildDenialPayloadFromRequest(
|
|
|
106
107
|
|
|
107
108
|
/** Builds the 403 Response, using hazo_api.fail() if available, otherwise hand-built. */
|
|
108
109
|
export async function buildForbiddenResponse(payload: PermissionDeniedPayload): Promise<Response> {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (apiMod?.fail) {
|
|
120
|
-
return apiMod.fail('FORBIDDEN', payload.user_friendly_message, {
|
|
121
|
-
status: 403,
|
|
122
|
-
details: {
|
|
123
|
-
missing_permissions: payload.missing_permissions,
|
|
124
|
-
user_friendly_message: payload.user_friendly_message,
|
|
125
|
-
permission_descriptions: payload.permission_descriptions,
|
|
126
|
-
action_label: payload.action_label,
|
|
127
|
-
origin_url: payload.origin_url,
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return new Response(
|
|
133
|
-
JSON.stringify({
|
|
134
|
-
ok: false,
|
|
135
|
-
error: {
|
|
136
|
-
code: 'FORBIDDEN',
|
|
137
|
-
message: payload.user_friendly_message,
|
|
138
|
-
details: {
|
|
139
|
-
missing_permissions: payload.missing_permissions,
|
|
140
|
-
permission_descriptions: payload.permission_descriptions,
|
|
141
|
-
action_label: payload.action_label,
|
|
142
|
-
origin_url: payload.origin_url,
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
}),
|
|
146
|
-
{ status: 403, headers: { 'Content-Type': 'application/json' } },
|
|
147
|
-
);
|
|
110
|
+
return buildEnvelopeResponse('FORBIDDEN', payload.user_friendly_message, {
|
|
111
|
+
status: 403,
|
|
112
|
+
details: {
|
|
113
|
+
missing_permissions: payload.missing_permissions,
|
|
114
|
+
user_friendly_message: payload.user_friendly_message,
|
|
115
|
+
permission_descriptions: payload.permission_descriptions,
|
|
116
|
+
action_label: payload.action_label,
|
|
117
|
+
origin_url: payload.origin_url,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
148
120
|
}
|
|
149
121
|
|
|
150
122
|
// section: wrapper
|
|
@@ -72,7 +72,16 @@ export function get_otp_config(): OtpConfig {
|
|
|
72
72
|
return {
|
|
73
73
|
auto_register: get_config_boolean(section, "otp_auto_register", d.auto_register),
|
|
74
74
|
code_ttl_seconds: get_config_number(section, "otp_code_ttl_seconds", d.code_ttl_seconds),
|
|
75
|
-
session_ttl_seconds
|
|
75
|
+
// `session_ttl_seconds` is the key the shipped sample config
|
|
76
|
+
// (config/hazo_auth_config.ini) actually uses. The original
|
|
77
|
+
// `otp_session_ttl_seconds` key is read as a fallback so any existing
|
|
78
|
+
// consumer config using the old name keeps working; when both are set,
|
|
79
|
+
// the new key wins.
|
|
80
|
+
session_ttl_seconds: get_config_number(
|
|
81
|
+
section,
|
|
82
|
+
"session_ttl_seconds",
|
|
83
|
+
get_config_number(section, "otp_session_ttl_seconds", d.session_ttl_seconds)
|
|
84
|
+
),
|
|
76
85
|
slide_when_within_seconds: get_config_number(
|
|
77
86
|
section,
|
|
78
87
|
"otp_slide_when_within_seconds",
|
|
@@ -60,21 +60,34 @@ function deep_merge(
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
63
|
+
* Normalizes a `hazo_users.app_user_data` jsonb column value to a plain
|
|
64
|
+
* object, returning null on anything else.
|
|
65
|
+
*
|
|
66
|
+
* The column is `jsonb`, and most hazo_connect adapters (e.g. `PgAdapter`,
|
|
67
|
+
* built on postgres.js with its default type parsers) already hand back a
|
|
68
|
+
* parsed JS value for a jsonb column — never a JSON string. This used to
|
|
69
|
+
* only accept a string and `JSON.parse` it, which silently discarded every
|
|
70
|
+
* real object value a caller like that (returning `null` even when data
|
|
71
|
+
* was genuinely set) instead of erroring loudly. Still accepts a string
|
|
72
|
+
* for any adapter that genuinely returns jsonb as unparsed text.
|
|
73
|
+
* @param value - The raw `app_user_data` column value, parsed or not
|
|
65
74
|
* @returns Parsed object or null
|
|
66
75
|
*/
|
|
67
|
-
function parse_app_user_data(
|
|
68
|
-
if (
|
|
76
|
+
function parse_app_user_data(value: unknown): Record<string, unknown> | null {
|
|
77
|
+
if (value === null || value === undefined || value === "") {
|
|
69
78
|
return null;
|
|
70
79
|
}
|
|
71
80
|
|
|
72
|
-
if (typeof
|
|
81
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
82
|
+
return value as Record<string, unknown>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (typeof value !== "string") {
|
|
73
86
|
return null;
|
|
74
87
|
}
|
|
75
88
|
|
|
76
89
|
try {
|
|
77
|
-
const parsed = JSON.parse(
|
|
90
|
+
const parsed = JSON.parse(value);
|
|
78
91
|
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
79
92
|
return parsed as Record<string, unknown>;
|
|
80
93
|
}
|
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import type { ProfilePicMenuMenuItem } from "../../../../lib/profile_pic_menu_config.server";
|
|
2
|
+
/**
|
|
3
|
+
* Per-sub-element class name overrides for `ProfilePicMenu`. Each value is
|
|
4
|
+
* merged (via `cn()`) alongside the corresponding `cls_profile_pic_menu_*`
|
|
5
|
+
* hook class already on that element — it never replaces the hook class, so
|
|
6
|
+
* existing CSS/test selectors keyed on `cls_profile_pic_menu_*` keep working.
|
|
7
|
+
* `item` targets menu items that aren't `logout`/`settings` (generic links,
|
|
8
|
+
* custom `action` items, and the shift-click "My Permissions" item).
|
|
9
|
+
*/
|
|
10
|
+
export type ProfilePicMenuClassNames = {
|
|
11
|
+
trigger?: string;
|
|
12
|
+
dropdown?: string;
|
|
13
|
+
avatar?: string;
|
|
14
|
+
fallback?: string;
|
|
15
|
+
item?: string;
|
|
16
|
+
separator?: string;
|
|
17
|
+
info?: string;
|
|
18
|
+
logout?: string;
|
|
19
|
+
settings?: string;
|
|
20
|
+
};
|
|
2
21
|
export type ProfilePicMenuProps = {
|
|
3
22
|
show_single_button?: boolean;
|
|
4
23
|
/** Undefined falls back to `t("profile_pic_menu.sign_up_label_default")`. */
|
|
@@ -24,6 +43,8 @@ export type ProfilePicMenuProps = {
|
|
|
24
43
|
/** Label for sidebar variant group. Undefined falls back to
|
|
25
44
|
* `t("profile_pic_menu.sidebar_group_label_default")`. */
|
|
26
45
|
sidebar_group_label?: string;
|
|
46
|
+
/** Optional per-sub-element class name overrides. See {@link ProfilePicMenuClassNames}. */
|
|
47
|
+
classNames?: ProfilePicMenuClassNames;
|
|
27
48
|
};
|
|
28
49
|
/**
|
|
29
50
|
* Profile picture menu component
|
|
@@ -34,5 +55,5 @@ export type ProfilePicMenuProps = {
|
|
|
34
55
|
* @param props - Component props including configuration options
|
|
35
56
|
* @returns Profile picture menu component
|
|
36
57
|
*/
|
|
37
|
-
export declare function ProfilePicMenu({ show_single_button, sign_up_label, sign_in_label, register_path, login_path, settings_path, logout_path, custom_menu_items, className, avatar_size, variant, sidebar_group_label, }: ProfilePicMenuProps): import("react").JSX.Element;
|
|
58
|
+
export declare function ProfilePicMenu({ show_single_button, sign_up_label, sign_in_label, register_path, login_path, settings_path, logout_path, custom_menu_items, className, avatar_size, variant, sidebar_group_label, classNames, }: ProfilePicMenuProps): import("react").JSX.Element;
|
|
38
59
|
//# sourceMappingURL=profile_pic_menu.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile_pic_menu.d.ts","sourceRoot":"","sources":["../../../../../src/components/layouts/shared/components/profile_pic_menu.tsx"],"names":[],"mappings":"AAqCA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;
|
|
1
|
+
{"version":3,"file":"profile_pic_menu.d.ts","sourceRoot":"","sources":["../../../../../src/components/layouts/shared/components/profile_pic_menu.tsx"],"names":[],"mappings":"AAqCA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AAK7F;;;;;;;GAOG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,6EAA6E;IAC7E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6EAA6E;IAC7E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;IACtC,OAAO,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IACjC;+DAC2D;IAC3D,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,2FAA2F;IAC3F,UAAU,CAAC,EAAE,wBAAwB,CAAC;CACvC,CAAC;AAGF;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,EAC7B,kBAA0B,EAC1B,aAAa,EACb,aAAa,EACb,aAAqC,EACrC,UAA+B,EAC/B,aAAwC,EACxC,WAAW,EACX,iBAAsB,EACtB,SAAS,EACT,WAAuB,EACvB,OAAoB,EACpB,mBAAmB,EACnB,UAAU,GACX,EAAE,mBAAmB,+BAiiBrB"}
|
|
@@ -17,6 +17,7 @@ import { Settings, LogOut, Shield } from "lucide-react";
|
|
|
17
17
|
import { toast } from "sonner";
|
|
18
18
|
import { use_auth_status, trigger_auth_status_refresh } from "../hooks/use_auth_status.js";
|
|
19
19
|
import { useHazoAuthConfig, useAuthT } from "../../../../contexts/hazo_auth_provider.js";
|
|
20
|
+
import { cn } from "../../../../lib/utils.js";
|
|
20
21
|
// section: component
|
|
21
22
|
/**
|
|
22
23
|
* Profile picture menu component
|
|
@@ -27,7 +28,7 @@ import { useHazoAuthConfig, useAuthT } from "../../../../contexts/hazo_auth_prov
|
|
|
27
28
|
* @param props - Component props including configuration options
|
|
28
29
|
* @returns Profile picture menu component
|
|
29
30
|
*/
|
|
30
|
-
export function ProfilePicMenu({ show_single_button = false, sign_up_label, sign_in_label, register_path = "/hazo_auth/register", login_path = "/hazo_auth/login", settings_path = "/hazo_auth/my_settings", logout_path, custom_menu_items = [], className, avatar_size = "default", variant = "dropdown", sidebar_group_label, }) {
|
|
31
|
+
export function ProfilePicMenu({ show_single_button = false, sign_up_label, sign_in_label, register_path = "/hazo_auth/register", login_path = "/hazo_auth/login", settings_path = "/hazo_auth/my_settings", logout_path, custom_menu_items = [], className, avatar_size = "default", variant = "dropdown", sidebar_group_label, classNames, }) {
|
|
31
32
|
const { apiBasePath } = useHazoAuthConfig();
|
|
32
33
|
const t = useAuthT();
|
|
33
34
|
const resolvedSignUpLabel = sign_up_label !== null && sign_up_label !== void 0 ? sign_up_label : t("profile_pic_menu.sign_up_label_default");
|
|
@@ -180,59 +181,59 @@ export function ProfilePicMenu({ show_single_button = false, sign_up_label, sign
|
|
|
180
181
|
if (variant === "sidebar") {
|
|
181
182
|
// Sidebar variant: show profile picture and name only, clicking opens dropdown
|
|
182
183
|
return (_jsxs(SidebarGroup, { className: `cls_profile_pic_menu_sidebar ${className || ""}`, children: [_jsx(SidebarGroupLabel, { className: "cls_profile_pic_menu_sidebar_label", children: resolvedSidebarGroupLabel }), _jsx(SidebarMenu, { className: "cls_profile_pic_menu_sidebar_menu", children: _jsxs(SidebarMenuItem, { className: "cls_profile_pic_menu_sidebar_user_info", children: [_jsxs(DropdownMenu, { onOpenChange: (open) => { if (!open)
|
|
183
|
-
setShiftKeyHeld(false); }, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx("button", { className: "cls_profile_pic_menu_sidebar_trigger w-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary rounded-md", "aria-label": t("profile_pic_menu.aria.profile_menu_default"), onClick: (e) => setShiftKeyHeld(e.shiftKey), children: _jsxs("div", { className: "cls_profile_pic_menu_sidebar_user flex items-center gap-3 px-2 py-2 hover:bg-sidebar-accent rounded-md transition-colors", children: [_jsxs(Avatar, { className: `cls_profile_pic_menu_avatar ${avatarSizeClasses[avatar_size]} cursor-pointer`, children: [_jsx(AvatarImage, { src: authStatus.profile_picture_url, alt: authStatus.name
|
|
184
|
+
setShiftKeyHeld(false); }, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx("button", { className: cn("cls_profile_pic_menu_sidebar_trigger w-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary rounded-md", classNames === null || classNames === void 0 ? void 0 : classNames.trigger), "aria-label": t("profile_pic_menu.aria.profile_menu_default"), onClick: (e) => setShiftKeyHeld(e.shiftKey), children: _jsxs("div", { className: "cls_profile_pic_menu_sidebar_user flex items-center gap-3 px-2 py-2 hover:bg-sidebar-accent rounded-md transition-colors", children: [_jsxs(Avatar, { className: cn(`cls_profile_pic_menu_avatar ${avatarSizeClasses[avatar_size]} cursor-pointer`, classNames === null || classNames === void 0 ? void 0 : classNames.avatar), children: [_jsx(AvatarImage, { src: authStatus.profile_picture_url, alt: authStatus.name
|
|
184
185
|
? t("profile_pic_menu.aria.avatar_alt_named", { name: authStatus.name })
|
|
185
|
-
: t("profile_pic_menu.aria.avatar_alt_default"), className: "cls_profile_pic_menu_image" }), _jsx(AvatarFallback, { className: "cls_profile_pic_menu_fallback bg-[var(--hazo-bg-emphasis)] text-[var(--hazo-text-muted)]", children: getInitials() })] }), authStatus.name && (_jsx("span", { className: "cls_profile_pic_menu_sidebar_user_name text-sm font-medium text-sidebar-foreground truncate", children: authStatus.name }))] }) }) }), _jsxs(DropdownMenuContent, { align: "end", className: "cls_profile_pic_menu_dropdown w-56", children: [menuItems.map((item) => {
|
|
186
|
+
: t("profile_pic_menu.aria.avatar_alt_default"), className: "cls_profile_pic_menu_image" }), _jsx(AvatarFallback, { className: cn("cls_profile_pic_menu_fallback bg-[var(--hazo-bg-emphasis)] text-[var(--hazo-text-muted)]", classNames === null || classNames === void 0 ? void 0 : classNames.fallback), children: getInitials() })] }), authStatus.name && (_jsx("span", { className: "cls_profile_pic_menu_sidebar_user_name text-sm font-medium text-sidebar-foreground truncate", children: authStatus.name }))] }) }) }), _jsxs(DropdownMenuContent, { align: "end", className: cn("cls_profile_pic_menu_dropdown w-56", classNames === null || classNames === void 0 ? void 0 : classNames.dropdown), children: [menuItems.map((item) => {
|
|
186
187
|
if (item.type === "separator") {
|
|
187
|
-
return _jsx(DropdownMenuSeparator, { className: "cls_profile_pic_menu_separator" }, item.id);
|
|
188
|
+
return _jsx(DropdownMenuSeparator, { className: cn("cls_profile_pic_menu_separator", classNames === null || classNames === void 0 ? void 0 : classNames.separator) }, item.id);
|
|
188
189
|
}
|
|
189
190
|
if (item.type === "info") {
|
|
190
|
-
return (_jsx("div", { className: "cls_profile_pic_menu_info", children: item.value && (_jsx("div", { className: "cls_profile_pic_menu_info_value px-2 py-1.5 text-sm text-foreground", children: item.value })) }, item.id));
|
|
191
|
+
return (_jsx("div", { className: cn("cls_profile_pic_menu_info", classNames === null || classNames === void 0 ? void 0 : classNames.info), children: item.value && (_jsx("div", { className: "cls_profile_pic_menu_info_value px-2 py-1.5 text-sm text-foreground", children: item.value })) }, item.id));
|
|
191
192
|
}
|
|
192
193
|
if (item.type === "link") {
|
|
193
194
|
// Special handling for logout
|
|
194
195
|
if (item.id === "default_logout") {
|
|
195
|
-
return (_jsxs(DropdownMenuItem, { onClick: handleLogout, disabled: isLoggingOut, className: "cls_profile_pic_menu_logout cursor-pointer text-destructive focus:text-destructive", children: [_jsx(LogOut, { className: "mr-2 h-4 w-4" }), isLoggingOut ? t("shared.logout.logging_out") : item.label] }, item.id));
|
|
196
|
+
return (_jsxs(DropdownMenuItem, { onClick: handleLogout, disabled: isLoggingOut, className: cn("cls_profile_pic_menu_logout cursor-pointer text-destructive focus:text-destructive", classNames === null || classNames === void 0 ? void 0 : classNames.logout), children: [_jsx(LogOut, { className: "mr-2 h-4 w-4" }), isLoggingOut ? t("shared.logout.logging_out") : item.label] }, item.id));
|
|
196
197
|
}
|
|
197
198
|
// Special handling for settings
|
|
198
199
|
if (item.id === "default_settings") {
|
|
199
|
-
return (_jsx(DropdownMenuItem, { asChild: true, className: "cls_profile_pic_menu_settings cursor-pointer", children: _jsxs(Link, { href: item.href || settings_path, children: [_jsx(Settings, { className: "mr-2 h-4 w-4" }), item.label] }) }, item.id));
|
|
200
|
+
return (_jsx(DropdownMenuItem, { asChild: true, className: cn("cls_profile_pic_menu_settings cursor-pointer", classNames === null || classNames === void 0 ? void 0 : classNames.settings), children: _jsxs(Link, { href: item.href || settings_path, children: [_jsx(Settings, { className: "mr-2 h-4 w-4" }), item.label] }) }, item.id));
|
|
200
201
|
}
|
|
201
202
|
// Generic link handling
|
|
202
|
-
return (_jsx(DropdownMenuItem, { asChild: true, className: "cls_profile_pic_menu_link cursor-pointer", children: _jsx(Link, { href: item.href || "#", children: item.label }) }, item.id));
|
|
203
|
+
return (_jsx(DropdownMenuItem, { asChild: true, className: cn("cls_profile_pic_menu_link cursor-pointer", classNames === null || classNames === void 0 ? void 0 : classNames.item), children: _jsx(Link, { href: item.href || "#", children: item.label }) }, item.id));
|
|
203
204
|
}
|
|
204
205
|
if (item.type === "action") {
|
|
205
|
-
return (_jsx(DropdownMenuItem, { onClick: item.onSelect, className: "cls_profile_pic_menu_action cursor-pointer", children: item.label }, item.id));
|
|
206
|
+
return (_jsx(DropdownMenuItem, { onClick: item.onSelect, className: cn("cls_profile_pic_menu_action cursor-pointer", classNames === null || classNames === void 0 ? void 0 : classNames.item), children: item.label }, item.id));
|
|
206
207
|
}
|
|
207
208
|
return null;
|
|
208
|
-
}), shiftKeyHeld && (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, { className: "cls_profile_pic_menu_separator" }), _jsxs(DropdownMenuItem, { onClick: () => setShowPermissionsDialog(true), className: "cls_profile_pic_menu_permissions cursor-pointer", children: [_jsx(Shield, { className: "mr-2 h-4 w-4" }), t("profile_pic_menu.permissions_label_default")] })] }))] })] }), _jsx(Dialog, { open: showPermissionsDialog, onOpenChange: setShowPermissionsDialog, children: _jsxs(DialogContent, { className: "cls_profile_pic_menu_permissions_dialog max-w-2xl max-h-[80vh] flex flex-col", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: t("profile_pic_menu.permissions_label_default") }), _jsx(DialogDescription, { children: t("profile_pic_menu.permissions_description_default") })] }), _jsx("div", { className: "flex-1 overflow-y-auto", children: _jsx(RolesMatrix, { user_id: authStatus.user_id, add_button_enabled: false, role_name_selection_enabled: false, permissions_read_only: true, show_save_cancel: false }) })] }) })] }) })] }));
|
|
209
|
+
}), shiftKeyHeld && (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, { className: cn("cls_profile_pic_menu_separator", classNames === null || classNames === void 0 ? void 0 : classNames.separator) }), _jsxs(DropdownMenuItem, { onClick: () => setShowPermissionsDialog(true), className: cn("cls_profile_pic_menu_permissions cursor-pointer", classNames === null || classNames === void 0 ? void 0 : classNames.item), children: [_jsx(Shield, { className: "mr-2 h-4 w-4" }), t("profile_pic_menu.permissions_label_default")] })] }))] })] }), _jsx(Dialog, { open: showPermissionsDialog, onOpenChange: setShowPermissionsDialog, children: _jsxs(DialogContent, { className: "cls_profile_pic_menu_permissions_dialog max-w-2xl max-h-[80vh] flex flex-col", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: t("profile_pic_menu.permissions_label_default") }), _jsx(DialogDescription, { children: t("profile_pic_menu.permissions_description_default") })] }), _jsx("div", { className: "flex-1 overflow-y-auto", children: _jsx(RolesMatrix, { user_id: authStatus.user_id, add_button_enabled: false, role_name_selection_enabled: false, permissions_read_only: true, show_save_cancel: false }) })] }) })] }) })] }));
|
|
209
210
|
}
|
|
210
211
|
// Default dropdown variant: show profile picture with dropdown menu
|
|
211
212
|
return (_jsxs("div", { className: `cls_profile_pic_menu ${className || ""}`, children: [_jsxs(DropdownMenu, { onOpenChange: (open) => { if (!open)
|
|
212
|
-
setShiftKeyHeld(false); }, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx("button", { className: "cls_profile_pic_menu_trigger focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary rounded-full", "aria-label": t("profile_pic_menu.aria.profile_menu_default"), onClick: (e) => setShiftKeyHeld(e.shiftKey), children: _jsxs(Avatar, { className: `cls_profile_pic_menu_avatar ${avatarSizeClasses[avatar_size]} cursor-pointer`, children: [_jsx(AvatarImage, { src: authStatus.profile_picture_url, alt: authStatus.name
|
|
213
|
+
setShiftKeyHeld(false); }, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx("button", { className: cn("cls_profile_pic_menu_trigger focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary rounded-full", classNames === null || classNames === void 0 ? void 0 : classNames.trigger), "aria-label": t("profile_pic_menu.aria.profile_menu_default"), onClick: (e) => setShiftKeyHeld(e.shiftKey), children: _jsxs(Avatar, { className: cn(`cls_profile_pic_menu_avatar ${avatarSizeClasses[avatar_size]} cursor-pointer`, classNames === null || classNames === void 0 ? void 0 : classNames.avatar), children: [_jsx(AvatarImage, { src: authStatus.profile_picture_url, alt: authStatus.name
|
|
213
214
|
? t("profile_pic_menu.aria.avatar_alt_named", { name: authStatus.name })
|
|
214
|
-
: t("profile_pic_menu.aria.avatar_alt_default"), className: "cls_profile_pic_menu_image" }), _jsx(AvatarFallback, { className: "cls_profile_pic_menu_fallback bg-[var(--hazo-bg-emphasis)] text-[var(--hazo-text-muted)]", children: getInitials() })] }) }) }), _jsxs(DropdownMenuContent, { align: "end", className: "cls_profile_pic_menu_dropdown w-56", children: [menuItems.map((item) => {
|
|
215
|
+
: t("profile_pic_menu.aria.avatar_alt_default"), className: "cls_profile_pic_menu_image" }), _jsx(AvatarFallback, { className: cn("cls_profile_pic_menu_fallback bg-[var(--hazo-bg-emphasis)] text-[var(--hazo-text-muted)]", classNames === null || classNames === void 0 ? void 0 : classNames.fallback), children: getInitials() })] }) }) }), _jsxs(DropdownMenuContent, { align: "end", className: cn("cls_profile_pic_menu_dropdown w-56", classNames === null || classNames === void 0 ? void 0 : classNames.dropdown), children: [menuItems.map((item) => {
|
|
215
216
|
if (item.type === "separator") {
|
|
216
|
-
return _jsx(DropdownMenuSeparator, { className: "cls_profile_pic_menu_separator" }, item.id);
|
|
217
|
+
return _jsx(DropdownMenuSeparator, { className: cn("cls_profile_pic_menu_separator", classNames === null || classNames === void 0 ? void 0 : classNames.separator) }, item.id);
|
|
217
218
|
}
|
|
218
219
|
if (item.type === "info") {
|
|
219
|
-
return (_jsx("div", { className: "cls_profile_pic_menu_info", children: item.value && (_jsx("div", { className: "cls_profile_pic_menu_info_value px-2 py-1.5 text-sm text-foreground", children: item.value })) }, item.id));
|
|
220
|
+
return (_jsx("div", { className: cn("cls_profile_pic_menu_info", classNames === null || classNames === void 0 ? void 0 : classNames.info), children: item.value && (_jsx("div", { className: "cls_profile_pic_menu_info_value px-2 py-1.5 text-sm text-foreground", children: item.value })) }, item.id));
|
|
220
221
|
}
|
|
221
222
|
if (item.type === "link") {
|
|
222
223
|
// Special handling for logout
|
|
223
224
|
if (item.id === "default_logout") {
|
|
224
|
-
return (_jsxs(DropdownMenuItem, { onClick: handleLogout, disabled: isLoggingOut, className: "cls_profile_pic_menu_logout cursor-pointer text-destructive focus:text-destructive", children: [_jsx(LogOut, { className: "mr-2 h-4 w-4" }), isLoggingOut ? t("shared.logout.logging_out") : item.label] }, item.id));
|
|
225
|
+
return (_jsxs(DropdownMenuItem, { onClick: handleLogout, disabled: isLoggingOut, className: cn("cls_profile_pic_menu_logout cursor-pointer text-destructive focus:text-destructive", classNames === null || classNames === void 0 ? void 0 : classNames.logout), children: [_jsx(LogOut, { className: "mr-2 h-4 w-4" }), isLoggingOut ? t("shared.logout.logging_out") : item.label] }, item.id));
|
|
225
226
|
}
|
|
226
227
|
// Special handling for settings
|
|
227
228
|
if (item.id === "default_settings") {
|
|
228
|
-
return (_jsx(DropdownMenuItem, { asChild: true, className: "cls_profile_pic_menu_settings cursor-pointer", children: _jsxs(Link, { href: item.href || settings_path, children: [_jsx(Settings, { className: "mr-2 h-4 w-4" }), item.label] }) }, item.id));
|
|
229
|
+
return (_jsx(DropdownMenuItem, { asChild: true, className: cn("cls_profile_pic_menu_settings cursor-pointer", classNames === null || classNames === void 0 ? void 0 : classNames.settings), children: _jsxs(Link, { href: item.href || settings_path, children: [_jsx(Settings, { className: "mr-2 h-4 w-4" }), item.label] }) }, item.id));
|
|
229
230
|
}
|
|
230
231
|
// Generic link handling
|
|
231
|
-
return (_jsx(DropdownMenuItem, { asChild: true, className: "cls_profile_pic_menu_link cursor-pointer", children: _jsx(Link, { href: item.href || "#", children: item.label }) }, item.id));
|
|
232
|
+
return (_jsx(DropdownMenuItem, { asChild: true, className: cn("cls_profile_pic_menu_link cursor-pointer", classNames === null || classNames === void 0 ? void 0 : classNames.item), children: _jsx(Link, { href: item.href || "#", children: item.label }) }, item.id));
|
|
232
233
|
}
|
|
233
234
|
if (item.type === "action") {
|
|
234
|
-
return (_jsx(DropdownMenuItem, { onClick: item.onSelect, className: "cls_profile_pic_menu_action cursor-pointer", children: item.label }, item.id));
|
|
235
|
+
return (_jsx(DropdownMenuItem, { onClick: item.onSelect, className: cn("cls_profile_pic_menu_action cursor-pointer", classNames === null || classNames === void 0 ? void 0 : classNames.item), children: item.label }, item.id));
|
|
235
236
|
}
|
|
236
237
|
return null;
|
|
237
|
-
}), shiftKeyHeld && (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, { className: "cls_profile_pic_menu_separator" }), _jsxs(DropdownMenuItem, { onClick: () => setShowPermissionsDialog(true), className: "cls_profile_pic_menu_permissions cursor-pointer", children: [_jsx(Shield, { className: "mr-2 h-4 w-4" }), t("profile_pic_menu.permissions_label_default")] })] }))] })] }), _jsx(Dialog, { open: showPermissionsDialog, onOpenChange: setShowPermissionsDialog, children: _jsxs(DialogContent, { className: "cls_profile_pic_menu_permissions_dialog max-w-2xl max-h-[80vh] flex flex-col", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: t("profile_pic_menu.permissions_label_default") }), _jsx(DialogDescription, { children: t("profile_pic_menu.permissions_description_default") })] }), _jsx("div", { className: "flex-1 overflow-y-auto", children: _jsx(RolesMatrix, { user_id: authStatus.user_id, add_button_enabled: false, role_name_selection_enabled: false, permissions_read_only: true, show_save_cancel: false }) })] }) })] }));
|
|
238
|
+
}), shiftKeyHeld && (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, { className: cn("cls_profile_pic_menu_separator", classNames === null || classNames === void 0 ? void 0 : classNames.separator) }), _jsxs(DropdownMenuItem, { onClick: () => setShowPermissionsDialog(true), className: cn("cls_profile_pic_menu_permissions cursor-pointer", classNames === null || classNames === void 0 ? void 0 : classNames.item), children: [_jsx(Shield, { className: "mr-2 h-4 w-4" }), t("profile_pic_menu.permissions_label_default")] })] }))] })] }), _jsx(Dialog, { open: showPermissionsDialog, onOpenChange: setShowPermissionsDialog, children: _jsxs(DialogContent, { className: "cls_profile_pic_menu_permissions_dialog max-w-2xl max-h-[80vh] flex flex-col", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: t("profile_pic_menu.permissions_label_default") }), _jsx(DialogDescription, { children: t("profile_pic_menu.permissions_description_default") })] }), _jsx("div", { className: "flex-1 overflow-y-auto", children: _jsx(RolesMatrix, { user_id: authStatus.user_id, add_button_enabled: false, role_name_selection_enabled: false, permissions_read_only: true, show_save_cancel: false }) })] }) })] }));
|
|
238
239
|
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
+
import { type ProfilePicMenuClassNames } from "./profile_pic_menu.js";
|
|
1
2
|
export type ProfilePicMenuWrapperProps = {
|
|
2
3
|
className?: string;
|
|
3
4
|
avatar_size?: "default" | "sm" | "lg";
|
|
4
5
|
variant?: "dropdown" | "sidebar";
|
|
5
6
|
/** Undefined falls back to `t("profile_pic_menu.sidebar_group_label_default")`. */
|
|
6
7
|
sidebar_group_label?: string;
|
|
8
|
+
/** Optional per-sub-element class name overrides. See {@link ProfilePicMenuClassNames}. */
|
|
9
|
+
classNames?: ProfilePicMenuClassNames;
|
|
7
10
|
};
|
|
8
11
|
/**
|
|
9
12
|
* Server wrapper component that loads profile picture menu configuration from hazo_auth_config.ini
|
|
10
13
|
* and passes it to the client ProfilePicMenu component
|
|
11
|
-
* @param props - Component props including className, avatar_size, variant, and
|
|
14
|
+
* @param props - Component props including className, avatar_size, variant, sidebar_group_label, and classNames
|
|
12
15
|
* @returns ProfilePicMenu component with loaded configuration
|
|
13
16
|
*/
|
|
14
|
-
export declare function ProfilePicMenuWrapper({ className, avatar_size, variant, sidebar_group_label, }: ProfilePicMenuWrapperProps): import("react").JSX.Element;
|
|
17
|
+
export declare function ProfilePicMenuWrapper({ className, avatar_size, variant, sidebar_group_label, classNames, }: ProfilePicMenuWrapperProps): import("react").JSX.Element;
|
|
15
18
|
//# sourceMappingURL=profile_pic_menu_wrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile_pic_menu_wrapper.d.ts","sourceRoot":"","sources":["../../../../../src/components/layouts/shared/components/profile_pic_menu_wrapper.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"profile_pic_menu_wrapper.d.ts","sourceRoot":"","sources":["../../../../../src/components/layouts/shared/components/profile_pic_menu_wrapper.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAInF,MAAM,MAAM,0BAA0B,GAAG;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;IACtC,OAAO,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IACjC,mFAAmF;IACnF,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,2FAA2F;IAC3F,UAAU,CAAC,EAAE,wBAAwB,CAAC;CACvC,CAAC;AAGF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,SAAS,EACT,WAAW,EACX,OAAoB,EACpB,mBAAmB,EACnB,UAAU,GACX,EAAE,0BAA0B,+BAoB5B"}
|
|
@@ -7,10 +7,10 @@ import { get_profile_pic_menu_config } from "../../../../lib/profile_pic_menu_co
|
|
|
7
7
|
/**
|
|
8
8
|
* Server wrapper component that loads profile picture menu configuration from hazo_auth_config.ini
|
|
9
9
|
* and passes it to the client ProfilePicMenu component
|
|
10
|
-
* @param props - Component props including className, avatar_size, variant, and
|
|
10
|
+
* @param props - Component props including className, avatar_size, variant, sidebar_group_label, and classNames
|
|
11
11
|
* @returns ProfilePicMenu component with loaded configuration
|
|
12
12
|
*/
|
|
13
|
-
export function ProfilePicMenuWrapper({ className, avatar_size, variant = "dropdown", sidebar_group_label, }) {
|
|
13
|
+
export function ProfilePicMenuWrapper({ className, avatar_size, variant = "dropdown", sidebar_group_label, classNames, }) {
|
|
14
14
|
const config = get_profile_pic_menu_config();
|
|
15
|
-
return (_jsx(ProfilePicMenu, { show_single_button: config.show_single_button, sign_up_label: config.sign_up_label, sign_in_label: config.sign_in_label, register_path: config.register_path, login_path: config.login_path, settings_path: config.settings_path, logout_path: config.logout_path, custom_menu_items: config.custom_menu_items, className: className, avatar_size: avatar_size, variant: variant, sidebar_group_label: sidebar_group_label }));
|
|
15
|
+
return (_jsx(ProfilePicMenu, { show_single_button: config.show_single_button, sign_up_label: config.sign_up_label, sign_in_label: config.sign_in_label, register_path: config.register_path, login_path: config.login_path, settings_path: config.settings_path, logout_path: config.logout_path, custom_menu_items: config.custom_menu_items, className: className, avatar_size: avatar_size, variant: variant, sidebar_group_label: sidebar_group_label, classNames: classNames }));
|
|
16
16
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
/**
|
|
3
|
+
* Builds an error Response in hazo_api's `fail()` envelope shape:
|
|
4
|
+
* `{ ok: false, error: { code, message, details? } }`.
|
|
5
|
+
*
|
|
6
|
+
* Uses the real `hazo_api.fail()` when hazo_auth's optional `hazo_api` peer
|
|
7
|
+
* is installed (richer HazoError enrichment, request-id/meta, etc.) —
|
|
8
|
+
* `optional_import`, not a literal `import('hazo_api')`, because a literal
|
|
9
|
+
* dynamic import of this optional peer breaks Turbopack builds (same
|
|
10
|
+
* reason `with_permission_issue_capture.server.ts`'s own `buildForbiddenResponse`
|
|
11
|
+
* already uses this pattern; this is that same helper generalized to any
|
|
12
|
+
* code/status/message, not just FORBIDDEN/403).
|
|
13
|
+
*
|
|
14
|
+
* Without hazo_api installed, hand-builds the identical top-level shape so
|
|
15
|
+
* a consumer's response parsing never has to care which path ran.
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildEnvelopeResponse(code: string, message: string, opts: {
|
|
18
|
+
status: number;
|
|
19
|
+
details?: unknown;
|
|
20
|
+
}): Promise<Response>;
|
|
21
|
+
//# sourceMappingURL=envelope_response.server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope_response.server.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/envelope_response.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAOrB;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAC1C,OAAO,CAAC,QAAQ,CAAC,CA2BnB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// file_description: builds a hazo_api-fail()-shaped JSON Response, using the real hazo_api.fail() when installed, otherwise a hand-built fallback matching the exact same envelope
|
|
2
|
+
// section: server_only_guard
|
|
3
|
+
import 'server-only';
|
|
4
|
+
// section: imports
|
|
5
|
+
import { optional_import } from 'hazo_core';
|
|
6
|
+
// section: envelope_response
|
|
7
|
+
/**
|
|
8
|
+
* Builds an error Response in hazo_api's `fail()` envelope shape:
|
|
9
|
+
* `{ ok: false, error: { code, message, details? } }`.
|
|
10
|
+
*
|
|
11
|
+
* Uses the real `hazo_api.fail()` when hazo_auth's optional `hazo_api` peer
|
|
12
|
+
* is installed (richer HazoError enrichment, request-id/meta, etc.) —
|
|
13
|
+
* `optional_import`, not a literal `import('hazo_api')`, because a literal
|
|
14
|
+
* dynamic import of this optional peer breaks Turbopack builds (same
|
|
15
|
+
* reason `with_permission_issue_capture.server.ts`'s own `buildForbiddenResponse`
|
|
16
|
+
* already uses this pattern; this is that same helper generalized to any
|
|
17
|
+
* code/status/message, not just FORBIDDEN/403).
|
|
18
|
+
*
|
|
19
|
+
* Without hazo_api installed, hand-builds the identical top-level shape so
|
|
20
|
+
* a consumer's response parsing never has to care which path ran.
|
|
21
|
+
*/
|
|
22
|
+
export async function buildEnvelopeResponse(code, message, opts) {
|
|
23
|
+
const apiMod = await optional_import('hazo_api');
|
|
24
|
+
if (apiMod === null || apiMod === void 0 ? void 0 : apiMod.fail) {
|
|
25
|
+
return apiMod.fail(code, message, Object.assign({ status: opts.status }, (opts.details !== undefined ? { details: opts.details } : {})));
|
|
26
|
+
}
|
|
27
|
+
return new Response(JSON.stringify({
|
|
28
|
+
ok: false,
|
|
29
|
+
error: Object.assign({ code,
|
|
30
|
+
message }, (opts.details !== undefined ? { details: opts.details } : {})),
|
|
31
|
+
}), { status: opts.status, headers: { 'Content-Type': 'application/json' } });
|
|
32
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hazo_get_auth.server.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/hazo_get_auth.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAGrB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAM1C,OAAO,KAAK,EACV,cAAc,EAEd,eAAe,EAGhB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"hazo_get_auth.server.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/hazo_get_auth.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAGrB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAM1C,OAAO,KAAK,EACV,cAAc,EAEd,eAAe,EAGhB,MAAM,cAAc,CAAC;AA+EtB;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAU1D;AAwUD;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,cAAc,CAAC,CAgQzB"}
|
|
@@ -20,19 +20,32 @@ import { GLOBAL_ADMIN_PERMISSION } from "../constants.js";
|
|
|
20
20
|
import { extract_scope_id_from_request } from "./scope_header.js";
|
|
21
21
|
// section: helpers
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
23
|
+
* Normalizes a `hazo_users.app_user_data` jsonb column value to a plain
|
|
24
|
+
* object, returning null on anything else.
|
|
25
|
+
*
|
|
26
|
+
* Most hazo_connect adapters (e.g. `PgAdapter`, built on postgres.js with
|
|
27
|
+
* its default type parsers) already hand back a parsed JS value for a
|
|
28
|
+
* jsonb column — never a JSON string. This used to only accept a string
|
|
29
|
+
* and `JSON.parse` it, which silently discarded every real object value
|
|
30
|
+
* (returning `null` even when data was genuinely set) instead of erroring
|
|
31
|
+
* loudly — see the identical fix/comment in app_user_data_service.ts's own
|
|
32
|
+
* copy of this helper. Still accepts a string for any adapter that
|
|
33
|
+
* genuinely returns jsonb as unparsed text.
|
|
34
|
+
* @param value - The raw `app_user_data` column value, parsed or not
|
|
25
35
|
* @returns Parsed object or null
|
|
26
36
|
*/
|
|
27
|
-
function parse_app_user_data(
|
|
28
|
-
if (
|
|
37
|
+
function parse_app_user_data(value) {
|
|
38
|
+
if (value === null || value === undefined || value === "") {
|
|
29
39
|
return null;
|
|
30
40
|
}
|
|
31
|
-
if (typeof
|
|
41
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
if (typeof value !== "string") {
|
|
32
45
|
return null;
|
|
33
46
|
}
|
|
34
47
|
try {
|
|
35
|
-
const parsed = JSON.parse(
|
|
48
|
+
const parsed = JSON.parse(value);
|
|
36
49
|
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
37
50
|
return parsed;
|
|
38
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with_auth.server.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/with_auth.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAGrB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACrB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"with_auth.server.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/with_auth.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAGrB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACrB,MAAM,cAAc,CAAC;AAYtB;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,IAAI,CAAC;IACpB,IAAI,EAAE,YAAY,CAAC;IACnB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACxC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,WAAW,EAAE,YAAY,EAAE,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gBAAgB,CAAC,EAAE,eAAe,CAAC;CACpC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG,uBAAuB,GAAG;IACrE,YAAY,EAAE,kBAAkB,CAAC;IACjC,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAAG;IAChD;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,KAAK,YAAY,CAAC,OAAO,IAAI;IAC3B,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,KAAK,oBAAoB,CAAC,OAAO,IAAI,CACnC,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,uBAAuB,EAC7B,MAAM,EAAE,OAAO,KACZ,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC;AAE1C;;GAEG;AACH,KAAK,0BAA0B,CAAC,OAAO,IAAI,CACzC,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,8BAA8B,EACpC,MAAM,EAAE,OAAO,KACZ,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC;AAE1C;;GAEG;AACH,KAAK,mBAAmB,CAAC,OAAO,IAAI,CAClC,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,gBAAgB,EACtB,MAAM,EAAE,OAAO,KACZ,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC;AAkF1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EACtD,OAAO,EAAE,0BAA0B,CAAC,OAAO,CAAC,EAC5C,OAAO,EAAE,eAAe,GAAG;IAAE,cAAc,EAAE,IAAI,CAAA;CAAE,GAClD,CACD,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,KAC5B,OAAO,CAAC,YAAY,CAAC,CAAC;AAE3B,wBAAgB,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EACtD,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,EACtC,OAAO,CAAC,EAAE,eAAe,GACxB,CACD,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,KAC5B,OAAO,CAAC,YAAY,CAAC,CAAC;AAmE3B;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAC9D,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,EACrC,OAAO,GAAE,iBAAsB,GAC9B,CACD,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,KAC5B,OAAO,CAAC,YAAY,CAAC,CAazB;AAID;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,uBAAuB,EAC7B,UAAU,EAAE,MAAM,GACjB,OAAO,CAET;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,uBAAuB,EAC7B,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAET;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,uBAAuB,EAC7B,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAET;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,uBAAuB,EAC7B,UAAU,EAAE,MAAM,GACjB,IAAI,CAQN;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,uBAAuB,EAC7B,WAAW,EAAE,MAAM,EAAE,GACpB,IAAI,CASN"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// file_description: withAuth/withOptionalAuth route handler wrappers that eliminate auth boilerplate
|
|
2
2
|
// section: server_only_guard
|
|
3
3
|
import "server-only";
|
|
4
|
-
// section: imports
|
|
5
|
-
import { NextResponse } from "next/server";
|
|
6
4
|
import { hazo_get_tenant_auth } from "./hazo_get_tenant_auth.server.js";
|
|
7
5
|
import { HazoAuthError, PermissionError, } from "./auth_types.js";
|
|
8
6
|
import { buildForbiddenResponse, buildDenialPayloadFromRequest, getPermissionDeniedHandler, } from "./with_permission_issue_capture.server.js";
|
|
7
|
+
import { buildEnvelopeResponse } from "./envelope_response.server.js";
|
|
9
8
|
import { get_app_permission_descriptions } from "../app_permissions_config.server.js";
|
|
10
9
|
// section: error_response_helper
|
|
11
10
|
/** Converts get_app_permission_descriptions()'s Map into the Record shape PermissionDeniedPayload expects. */
|
|
@@ -39,7 +38,9 @@ async function respond_permission_denied(payload) {
|
|
|
39
38
|
async function handle_auth_error(error, request) {
|
|
40
39
|
var _a, _b, _c, _d, _e;
|
|
41
40
|
if (error instanceof HazoAuthError) {
|
|
42
|
-
return
|
|
41
|
+
return (await buildEnvelopeResponse(error.code, error.message, {
|
|
42
|
+
status: error.status_code,
|
|
43
|
+
}));
|
|
43
44
|
}
|
|
44
45
|
if (error instanceof PermissionError) {
|
|
45
46
|
const descriptions = get_app_permission_descriptions((_a = error.missing_permissions) !== null && _a !== void 0 ? _a : []);
|
|
@@ -53,7 +54,9 @@ async function handle_auth_error(error, request) {
|
|
|
53
54
|
return respond_permission_denied(payload);
|
|
54
55
|
}
|
|
55
56
|
console.error("Unexpected error in route handler:", error);
|
|
56
|
-
return
|
|
57
|
+
return (await buildEnvelopeResponse("INTERNAL_ERROR", "Internal server error", {
|
|
58
|
+
status: 500,
|
|
59
|
+
}));
|
|
57
60
|
}
|
|
58
61
|
/**
|
|
59
62
|
* Resolves params from Next.js route context, handling missing context gracefully
|
|
@@ -70,7 +73,7 @@ export function withAuth(handler, options = {}) {
|
|
|
70
73
|
try {
|
|
71
74
|
const auth = await hazo_get_tenant_auth(request, options);
|
|
72
75
|
if (!auth.authenticated) {
|
|
73
|
-
return
|
|
76
|
+
return (await buildEnvelopeResponse("AUTHENTICATION_REQUIRED", "Authentication required", { status: 401 }));
|
|
74
77
|
}
|
|
75
78
|
// Check permissions if required_permissions were specified
|
|
76
79
|
if (((_a = options.required_permissions) === null || _a === void 0 ? void 0 : _a.length) && !auth.permission_ok) {
|
|
@@ -87,10 +90,7 @@ export function withAuth(handler, options = {}) {
|
|
|
87
90
|
}
|
|
88
91
|
// Check tenant requirement
|
|
89
92
|
if (options.require_tenant && !auth.organization) {
|
|
90
|
-
return
|
|
91
|
-
error: "Organization context required",
|
|
92
|
-
code: "TENANT_REQUIRED",
|
|
93
|
-
}, { status: 403 });
|
|
93
|
+
return (await buildEnvelopeResponse("TENANT_REQUIRED", "Organization context required", { status: 403 }));
|
|
94
94
|
}
|
|
95
95
|
const params = await resolve_params(context);
|
|
96
96
|
// Cast is safe: overloads ensure correct handler type matches options
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with_permission_issue_capture.server.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/with_permission_issue_capture.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAGrB,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"with_permission_issue_capture.server.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/with_permission_issue_capture.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAGrB,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAU/C,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChD,qBAAqB,EAAE,MAAM,CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAUD,wBAAgB,0BAA0B,CACxC,EAAE,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAC7D,IAAI,CAEN;AAED,wBAAgB,0BAA0B,eARN,uBAAuB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,SAUnF;AAID,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,uBAAuB,GAC7B,uBAAuB,CAoCzB;AAID,yFAAyF;AACzF,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAWhG;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,EACpD,IAAI,EAAE;IAAE,oBAAoB,EAAE,MAAM,EAAE,CAAA;CAAE,GACvC,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CA0D7C"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// file_description: Route handler wrapper that catches PermissionError and returns a structured hazo_api fail() 403
|
|
2
2
|
// section: server-only-guard
|
|
3
3
|
import 'server-only';
|
|
4
|
-
import { createLogger
|
|
4
|
+
import { createLogger } from 'hazo_core';
|
|
5
5
|
import { PermissionError } from './auth_types.js';
|
|
6
6
|
import { hazo_get_auth } from './hazo_get_auth.server.js';
|
|
7
|
+
import { buildEnvelopeResponse } from './envelope_response.server.js';
|
|
7
8
|
const log = createLogger('hazo_auth:permission_capture');
|
|
8
9
|
// section: global_callback
|
|
9
10
|
/**
|
|
@@ -56,34 +57,16 @@ export function buildDenialPayloadFromRequest(request, parts) {
|
|
|
56
57
|
// section: response_helper
|
|
57
58
|
/** Builds the 403 Response, using hazo_api.fail() if available, otherwise hand-built. */
|
|
58
59
|
export async function buildForbiddenResponse(payload) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
user_friendly_message: payload.user_friendly_message,
|
|
68
|
-
permission_descriptions: payload.permission_descriptions,
|
|
69
|
-
action_label: payload.action_label,
|
|
70
|
-
origin_url: payload.origin_url,
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return new Response(JSON.stringify({
|
|
75
|
-
ok: false,
|
|
76
|
-
error: {
|
|
77
|
-
code: 'FORBIDDEN',
|
|
78
|
-
message: payload.user_friendly_message,
|
|
79
|
-
details: {
|
|
80
|
-
missing_permissions: payload.missing_permissions,
|
|
81
|
-
permission_descriptions: payload.permission_descriptions,
|
|
82
|
-
action_label: payload.action_label,
|
|
83
|
-
origin_url: payload.origin_url,
|
|
84
|
-
},
|
|
60
|
+
return buildEnvelopeResponse('FORBIDDEN', payload.user_friendly_message, {
|
|
61
|
+
status: 403,
|
|
62
|
+
details: {
|
|
63
|
+
missing_permissions: payload.missing_permissions,
|
|
64
|
+
user_friendly_message: payload.user_friendly_message,
|
|
65
|
+
permission_descriptions: payload.permission_descriptions,
|
|
66
|
+
action_label: payload.action_label,
|
|
67
|
+
origin_url: payload.origin_url,
|
|
85
68
|
},
|
|
86
|
-
})
|
|
69
|
+
});
|
|
87
70
|
}
|
|
88
71
|
// section: wrapper
|
|
89
72
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otp_config.server.d.ts","sourceRoot":"","sources":["../../src/lib/otp_config.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAWrB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;CAiBtB,CAAC;AAGX,MAAM,MAAM,SAAS,GAAG;IACtB,8FAA8F;IAC9F,aAAa,EAAE,OAAO,CAAC;IACvB,uDAAuD;IACvD,gBAAgB,EAAE,MAAM,CAAC;IACzB,qFAAqF;IACrF,mBAAmB,EAAE,MAAM,CAAC;IAC5B,oFAAoF;IACpF,yBAAyB,EAAE,MAAM,CAAC;IAClC,kFAAkF;IAClF,oBAAoB,EAAE,MAAM,CAAC;IAC7B,6DAA6D;IAC7D,+BAA+B,EAAE,MAAM,CAAC;IACxC,+EAA+E;IAC/E,iBAAiB,EAAE,MAAM,CAAC;IAC1B,0DAA0D;IAC1D,4BAA4B,EAAE,MAAM,CAAC;IACrC,wEAAwE;IACxE,mBAAmB,EAAE,MAAM,CAAC;IAC5B,6DAA6D;IAC7D,oBAAoB,EAAE,MAAM,CAAC;IAC7B,uDAAuD;IACvD,qBAAqB,EAAE,MAAM,CAAC;IAC9B,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,2IAA2I;IAC3I,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B,CAAC;AAGF;;;GAGG;AACH,wBAAgB,cAAc,IAAI,SAAS,
|
|
1
|
+
{"version":3,"file":"otp_config.server.d.ts","sourceRoot":"","sources":["../../src/lib/otp_config.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAWrB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;CAiBtB,CAAC;AAGX,MAAM,MAAM,SAAS,GAAG;IACtB,8FAA8F;IAC9F,aAAa,EAAE,OAAO,CAAC;IACvB,uDAAuD;IACvD,gBAAgB,EAAE,MAAM,CAAC;IACzB,qFAAqF;IACrF,mBAAmB,EAAE,MAAM,CAAC;IAC5B,oFAAoF;IACpF,yBAAyB,EAAE,MAAM,CAAC;IAClC,kFAAkF;IAClF,oBAAoB,EAAE,MAAM,CAAC;IAC7B,6DAA6D;IAC7D,+BAA+B,EAAE,MAAM,CAAC;IACxC,+EAA+E;IAC/E,iBAAiB,EAAE,MAAM,CAAC;IAC1B,0DAA0D;IAC1D,4BAA4B,EAAE,MAAM,CAAC;IACrC,wEAAwE;IACxE,mBAAmB,EAAE,MAAM,CAAC;IAC5B,6DAA6D;IAC7D,oBAAoB,EAAE,MAAM,CAAC;IAC7B,uDAAuD;IACvD,qBAAqB,EAAE,MAAM,CAAC;IAC9B,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,2IAA2I;IAC3I,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B,CAAC;AAGF;;;GAGG;AACH,wBAAgB,cAAc,IAAI,SAAS,CA0C1C;AAED;;;GAGG;AACH,wBAAgB,iCAAiC,IAAI,MAAM,CAE1D"}
|
|
@@ -33,7 +33,12 @@ export function get_otp_config() {
|
|
|
33
33
|
return {
|
|
34
34
|
auto_register: get_config_boolean(section, "otp_auto_register", d.auto_register),
|
|
35
35
|
code_ttl_seconds: get_config_number(section, "otp_code_ttl_seconds", d.code_ttl_seconds),
|
|
36
|
-
session_ttl_seconds
|
|
36
|
+
// `session_ttl_seconds` is the key the shipped sample config
|
|
37
|
+
// (config/hazo_auth_config.ini) actually uses. The original
|
|
38
|
+
// `otp_session_ttl_seconds` key is read as a fallback so any existing
|
|
39
|
+
// consumer config using the old name keeps working; when both are set,
|
|
40
|
+
// the new key wins.
|
|
41
|
+
session_ttl_seconds: get_config_number(section, "session_ttl_seconds", get_config_number(section, "otp_session_ttl_seconds", d.session_ttl_seconds)),
|
|
37
42
|
slide_when_within_seconds: get_config_number(section, "otp_slide_when_within_seconds", d.slide_when_within_seconds),
|
|
38
43
|
email_rate_limit_max: get_config_number(section, "otp_email_rate_limit_max", d.email_rate_limit_max),
|
|
39
44
|
email_rate_limit_window_seconds: get_config_number(section, "otp_email_rate_limit_window_seconds", d.email_rate_limit_window_seconds),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app_user_data_service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/app_user_data_service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAQvD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,4FAA4F;IAC5F,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;
|
|
1
|
+
{"version":3,"file":"app_user_data_service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/app_user_data_service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAQvD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,4FAA4F;IAC5F,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAoGF;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,iBAAiB,CAAC,CAwC5B;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,iBAAiB,CAAC,CA+D5B;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,iBAAiB,CAAC,CAiD5B"}
|
|
@@ -32,19 +32,31 @@ function deep_merge(target, source) {
|
|
|
32
32
|
return result;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
35
|
+
* Normalizes a `hazo_users.app_user_data` jsonb column value to a plain
|
|
36
|
+
* object, returning null on anything else.
|
|
37
|
+
*
|
|
38
|
+
* The column is `jsonb`, and most hazo_connect adapters (e.g. `PgAdapter`,
|
|
39
|
+
* built on postgres.js with its default type parsers) already hand back a
|
|
40
|
+
* parsed JS value for a jsonb column — never a JSON string. This used to
|
|
41
|
+
* only accept a string and `JSON.parse` it, which silently discarded every
|
|
42
|
+
* real object value a caller like that (returning `null` even when data
|
|
43
|
+
* was genuinely set) instead of erroring loudly. Still accepts a string
|
|
44
|
+
* for any adapter that genuinely returns jsonb as unparsed text.
|
|
45
|
+
* @param value - The raw `app_user_data` column value, parsed or not
|
|
37
46
|
* @returns Parsed object or null
|
|
38
47
|
*/
|
|
39
|
-
function parse_app_user_data(
|
|
40
|
-
if (
|
|
48
|
+
function parse_app_user_data(value) {
|
|
49
|
+
if (value === null || value === undefined || value === "") {
|
|
41
50
|
return null;
|
|
42
51
|
}
|
|
43
|
-
if (typeof
|
|
52
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
if (typeof value !== "string") {
|
|
44
56
|
return null;
|
|
45
57
|
}
|
|
46
58
|
try {
|
|
47
|
-
const parsed = JSON.parse(
|
|
59
|
+
const parsed = JSON.parse(value);
|
|
48
60
|
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
49
61
|
return parsed;
|
|
50
62
|
}
|
package/package.json
CHANGED