hazo_auth 1.6.6 → 3.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.
- package/README.md +212 -12
- package/SETUP_CHECKLIST.md +81 -1
- package/dist/app/api/hazo_auth/login/route.d.ts.map +1 -1
- package/dist/app/api/hazo_auth/login/route.js +25 -0
- package/dist/app/api/hazo_auth/logout/route.d.ts.map +1 -1
- package/dist/app/api/hazo_auth/logout/route.js +5 -0
- package/dist/components/layouts/email_verification/hooks/use_email_verification.d.ts.map +1 -1
- package/dist/components/layouts/email_verification/hooks/use_email_verification.js +5 -3
- package/dist/components/layouts/email_verification/index.d.ts +2 -1
- package/dist/components/layouts/email_verification/index.d.ts.map +1 -1
- package/dist/components/layouts/forgot_password/hooks/use_forgot_password_form.d.ts.map +1 -1
- package/dist/components/layouts/forgot_password/hooks/use_forgot_password_form.js +3 -1
- package/dist/components/layouts/forgot_password/index.d.ts +2 -1
- package/dist/components/layouts/forgot_password/index.d.ts.map +1 -1
- package/dist/components/layouts/login/hooks/use_login_form.d.ts.map +1 -1
- package/dist/components/layouts/login/hooks/use_login_form.js +3 -1
- package/dist/components/layouts/login/index.d.ts +2 -1
- package/dist/components/layouts/login/index.d.ts.map +1 -1
- package/dist/components/layouts/my_settings/components/profile_picture_dialog.d.ts.map +1 -1
- package/dist/components/layouts/my_settings/components/profile_picture_dialog.js +3 -1
- package/dist/components/layouts/my_settings/components/profile_picture_library_tab.d.ts.map +1 -1
- package/dist/components/layouts/my_settings/components/profile_picture_library_tab.js +4 -2
- package/dist/components/layouts/my_settings/hooks/use_my_settings.d.ts.map +1 -1
- package/dist/components/layouts/my_settings/hooks/use_my_settings.js +7 -5
- package/dist/components/layouts/my_settings/index.d.ts +2 -1
- package/dist/components/layouts/my_settings/index.d.ts.map +1 -1
- package/dist/components/layouts/my_settings/index.js +3 -2
- package/dist/components/layouts/register/hooks/use_register_form.d.ts.map +1 -1
- package/dist/components/layouts/register/hooks/use_register_form.js +37 -7
- package/dist/components/layouts/register/index.d.ts +2 -1
- package/dist/components/layouts/register/index.d.ts.map +1 -1
- package/dist/components/layouts/reset_password/hooks/use_reset_password_form.d.ts.map +1 -1
- package/dist/components/layouts/reset_password/hooks/use_reset_password_form.js +4 -2
- package/dist/components/layouts/reset_password/index.d.ts +2 -1
- package/dist/components/layouts/reset_password/index.d.ts.map +1 -1
- package/dist/components/layouts/shared/components/already_logged_in_guard.d.ts +2 -1
- package/dist/components/layouts/shared/components/already_logged_in_guard.d.ts.map +1 -1
- package/dist/components/layouts/shared/components/logout_button.d.ts.map +1 -1
- package/dist/components/layouts/shared/components/logout_button.js +3 -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 +8 -4
- package/dist/components/layouts/shared/components/two_column_auth_layout.d.ts +2 -1
- package/dist/components/layouts/shared/components/two_column_auth_layout.d.ts.map +1 -1
- package/dist/components/layouts/shared/components/visual_panel.d.ts +2 -1
- package/dist/components/layouts/shared/components/visual_panel.d.ts.map +1 -1
- package/dist/components/layouts/shared/components/visual_panel.js +2 -1
- package/dist/components/layouts/shared/hooks/use_auth_status.d.ts.map +1 -1
- package/dist/components/layouts/shared/hooks/use_auth_status.js +4 -2
- package/dist/components/layouts/shared/hooks/use_hazo_auth.d.ts.map +1 -1
- package/dist/components/layouts/shared/hooks/use_hazo_auth.js +4 -2
- package/dist/components/layouts/shared/index.d.ts +0 -2
- package/dist/components/layouts/shared/index.d.ts.map +1 -1
- package/dist/components/layouts/shared/index.js +2 -2
- package/dist/components/layouts/user_management/components/roles_matrix.d.ts.map +1 -1
- package/dist/components/layouts/user_management/components/roles_matrix.js +8 -6
- package/dist/components/layouts/user_management/index.d.ts.map +1 -1
- package/dist/components/layouts/user_management/index.js +15 -13
- package/dist/contexts/hazo_auth_config.d.ts +18 -0
- package/dist/contexts/hazo_auth_config.d.ts.map +1 -0
- package/dist/contexts/hazo_auth_config.js +10 -0
- package/dist/contexts/hazo_auth_provider.d.ts +73 -0
- package/dist/contexts/hazo_auth_provider.d.ts.map +1 -0
- package/dist/contexts/hazo_auth_provider.js +82 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/lib/auth/hazo_get_auth.server.d.ts.map +1 -1
- package/dist/lib/auth/hazo_get_auth.server.js +31 -3
- package/dist/lib/auth/session_token_validator.edge.d.ts +15 -0
- package/dist/lib/auth/session_token_validator.edge.d.ts.map +1 -0
- package/dist/lib/auth/session_token_validator.edge.js +64 -0
- package/dist/lib/config/default_config.d.ts +237 -0
- package/dist/lib/config/default_config.d.ts.map +1 -0
- package/dist/lib/config/default_config.js +159 -0
- package/dist/lib/email_verification_config.server.d.ts +4 -0
- package/dist/lib/email_verification_config.server.d.ts.map +1 -1
- package/dist/lib/email_verification_config.server.js +12 -0
- package/dist/lib/forgot_password_config.server.d.ts +4 -0
- package/dist/lib/forgot_password_config.server.d.ts.map +1 -1
- package/dist/lib/forgot_password_config.server.js +12 -0
- package/dist/lib/login_config.server.d.ts +4 -0
- package/dist/lib/login_config.server.d.ts.map +1 -1
- package/dist/lib/login_config.server.js +10 -0
- package/dist/lib/password_requirements_config.server.d.ts +1 -1
- package/dist/lib/password_requirements_config.server.d.ts.map +1 -1
- package/dist/lib/password_requirements_config.server.js +8 -7
- package/dist/lib/register_config.server.d.ts +4 -0
- package/dist/lib/register_config.server.d.ts.map +1 -1
- package/dist/lib/register_config.server.js +10 -0
- package/dist/lib/reset_password_config.server.d.ts +4 -0
- package/dist/lib/reset_password_config.server.d.ts.map +1 -1
- package/dist/lib/reset_password_config.server.js +10 -0
- package/dist/lib/services/session_token_service.d.ts +27 -0
- package/dist/lib/services/session_token_service.d.ts.map +1 -0
- package/dist/lib/services/session_token_service.js +130 -0
- package/dist/page_components/forgot_password.d.ts.map +1 -1
- package/dist/page_components/forgot_password.js +14 -0
- package/dist/page_components/login.d.ts +4 -0
- package/dist/page_components/login.d.ts.map +1 -1
- package/dist/page_components/login.js +14 -0
- package/dist/page_components/register.d.ts.map +1 -1
- package/dist/page_components/register.js +14 -0
- package/dist/page_components/reset_password.d.ts.map +1 -1
- package/dist/page_components/reset_password.js +14 -0
- package/dist/page_components/verify_email.d.ts.map +1 -1
- package/dist/page_components/verify_email.js +14 -0
- package/dist/pages/forgot_password.d.ts +52 -0
- package/dist/pages/forgot_password.d.ts.map +1 -0
- package/dist/pages/forgot_password.js +41 -0
- package/dist/pages/index.d.ts +33 -0
- package/dist/pages/index.d.ts.map +1 -0
- package/dist/pages/index.js +28 -0
- package/dist/pages/login.d.ts +43 -0
- package/dist/pages/login.d.ts.map +1 -0
- package/dist/pages/login.js +45 -0
- package/dist/pages/my_settings.d.ts +54 -0
- package/dist/pages/my_settings.d.ts.map +1 -0
- package/dist/pages/my_settings.js +57 -0
- package/dist/pages/register.d.ts +44 -0
- package/dist/pages/register.d.ts.map +1 -0
- package/dist/pages/register.js +46 -0
- package/dist/pages/reset_password.d.ts +43 -0
- package/dist/pages/reset_password.d.ts.map +1 -0
- package/dist/pages/reset_password.js +42 -0
- package/dist/pages/verify_email.d.ts +52 -0
- package/dist/pages/verify_email.d.ts.map +1 -0
- package/dist/pages/verify_email.js +41 -0
- package/dist/server/middleware.d.ts +3 -0
- package/dist/server/middleware.d.ts.map +1 -0
- package/dist/server/middleware.js +5 -0
- package/dist/server_pages/forgot_password.d.ts +53 -0
- package/dist/server_pages/forgot_password.d.ts.map +1 -0
- package/dist/server_pages/forgot_password.js +40 -0
- package/dist/server_pages/forgot_password_client_wrapper.d.ts +15 -0
- package/dist/server_pages/forgot_password_client_wrapper.d.ts.map +1 -0
- package/dist/server_pages/forgot_password_client_wrapper.js +27 -0
- package/dist/server_pages/index.d.ts +13 -0
- package/dist/server_pages/index.d.ts.map +1 -0
- package/dist/server_pages/index.js +7 -0
- package/dist/server_pages/login.d.ts +43 -0
- package/dist/server_pages/login.d.ts.map +1 -0
- package/dist/server_pages/login.js +39 -0
- package/dist/server_pages/login_client_wrapper.d.ts +13 -0
- package/dist/server_pages/login_client_wrapper.d.ts.map +1 -0
- package/dist/server_pages/login_client_wrapper.js +29 -0
- package/dist/server_pages/my_settings.d.ts +53 -0
- package/dist/server_pages/my_settings.d.ts.map +1 -0
- package/dist/server_pages/my_settings.js +57 -0
- package/dist/server_pages/register.d.ts +45 -0
- package/dist/server_pages/register.d.ts.map +1 -0
- package/dist/server_pages/register.js +41 -0
- package/dist/server_pages/register_client_wrapper.d.ts +13 -0
- package/dist/server_pages/register_client_wrapper.d.ts.map +1 -0
- package/dist/server_pages/register_client_wrapper.js +27 -0
- package/dist/server_pages/reset_password.d.ts +44 -0
- package/dist/server_pages/reset_password.d.ts.map +1 -0
- package/dist/server_pages/reset_password.js +40 -0
- package/dist/server_pages/reset_password_client_wrapper.d.ts +13 -0
- package/dist/server_pages/reset_password_client_wrapper.d.ts.map +1 -0
- package/dist/server_pages/reset_password_client_wrapper.js +27 -0
- package/dist/server_pages/verify_email.d.ts +53 -0
- package/dist/server_pages/verify_email.d.ts.map +1 -0
- package/dist/server_pages/verify_email.js +40 -0
- package/dist/server_pages/verify_email_client_wrapper.d.ts +15 -0
- package/dist/server_pages/verify_email_client_wrapper.d.ts.map +1 -0
- package/dist/server_pages/verify_email_client_wrapper.js +27 -0
- package/package.json +39 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_hazo_auth.d.ts","sourceRoot":"","sources":["../../../../../src/components/layouts/shared/hooks/use_hazo_auth.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"use_hazo_auth.d.ts","sourceRoot":"","sources":["../../../../../src/components/layouts/shared/hooks/use_hazo_auth.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAKtE;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,cAAc,GAAG;IAC/C;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB;;OAEG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAOF;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,IAAI,CAMhD;AAID;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,CAAC,EAAE,kBAAkB,GAC3B,iBAAiB,CAoFnB"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"use client";
|
|
4
4
|
// section: imports
|
|
5
5
|
import { useState, useEffect, useCallback } from "react";
|
|
6
|
+
import { useHazoAuthConfig } from "../../../../contexts/hazo_auth_provider";
|
|
6
7
|
// section: constants
|
|
7
8
|
const AUTH_STATUS_CHANGE_EVENT = "hazo_auth_status_change";
|
|
8
9
|
// section: helpers
|
|
@@ -23,6 +24,7 @@ export function trigger_hazo_auth_refresh() {
|
|
|
23
24
|
* @returns UseHazoAuthResult with auth data, loading state, and refetch function
|
|
24
25
|
*/
|
|
25
26
|
export function use_hazo_auth(options) {
|
|
27
|
+
const { apiBasePath } = useHazoAuthConfig();
|
|
26
28
|
const [authResult, setAuthResult] = useState({
|
|
27
29
|
authenticated: false,
|
|
28
30
|
user: null,
|
|
@@ -39,7 +41,7 @@ export function use_hazo_auth(options) {
|
|
|
39
41
|
setLoading(true);
|
|
40
42
|
setError(null);
|
|
41
43
|
try {
|
|
42
|
-
const response = await fetch(
|
|
44
|
+
const response = await fetch(`${apiBasePath}/get_auth`, {
|
|
43
45
|
method: "POST",
|
|
44
46
|
headers: {
|
|
45
47
|
"Content-Type": "application/json",
|
|
@@ -72,7 +74,7 @@ export function use_hazo_auth(options) {
|
|
|
72
74
|
finally {
|
|
73
75
|
setLoading(false);
|
|
74
76
|
}
|
|
75
|
-
}, [options === null || options === void 0 ? void 0 : options.required_permissions, options === null || options === void 0 ? void 0 : options.strict, options === null || options === void 0 ? void 0 : options.skip]);
|
|
77
|
+
}, [apiBasePath, options === null || options === void 0 ? void 0 : options.required_permissions, options === null || options === void 0 ? void 0 : options.strict, options === null || options === void 0 ? void 0 : options.skip]);
|
|
76
78
|
useEffect(() => {
|
|
77
79
|
// Fetch auth status on mount
|
|
78
80
|
void fetchAuth();
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { AlreadyLoggedInGuard } from "./components/already_logged_in_guard";
|
|
2
|
-
export { AuthPageShell } from "./components/auth_page_shell";
|
|
3
2
|
export { FieldErrorMessage } from "./components/field_error_message";
|
|
4
3
|
export { FormActionButtons } from "./components/form_action_buttons";
|
|
5
4
|
export { FormFieldWrapper } from "./components/form_field_wrapper";
|
|
@@ -8,7 +7,6 @@ export { LogoutButton } from "./components/logout_button";
|
|
|
8
7
|
export { PasswordField } from "./components/password_field";
|
|
9
8
|
export { ProfilePicMenuWrapper } from "./components/profile_pic_menu_wrapper";
|
|
10
9
|
export { ProfilePicMenu } from "./components/profile_pic_menu";
|
|
11
|
-
export { SidebarLayoutWrapper } from "./components/sidebar_layout_wrapper";
|
|
12
10
|
export { StandaloneLayoutWrapper } from "./components/standalone_layout_wrapper";
|
|
13
11
|
export { TwoColumnAuthLayout } from "./components/two_column_auth_layout";
|
|
14
12
|
export { UnauthorizedGuard } from "./components/unauthorized_guard";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/layouts/shared/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/layouts/shared/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAE5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACjF,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAGnF,cAAc,+BAA+B,CAAC;AAG9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,cAAc,oBAAoB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// file_description: barrel export for shared layout components, hooks, and utilities
|
|
2
2
|
// section: component_exports
|
|
3
3
|
export { AlreadyLoggedInGuard } from "./components/already_logged_in_guard";
|
|
4
|
-
|
|
4
|
+
// AuthPageShell - NOT exported (test workspace component only)
|
|
5
5
|
export { FieldErrorMessage } from "./components/field_error_message";
|
|
6
6
|
export { FormActionButtons } from "./components/form_action_buttons";
|
|
7
7
|
export { FormFieldWrapper } from "./components/form_field_wrapper";
|
|
@@ -10,7 +10,7 @@ export { LogoutButton } from "./components/logout_button";
|
|
|
10
10
|
export { PasswordField } from "./components/password_field";
|
|
11
11
|
export { ProfilePicMenuWrapper } from "./components/profile_pic_menu_wrapper";
|
|
12
12
|
export { ProfilePicMenu } from "./components/profile_pic_menu";
|
|
13
|
-
|
|
13
|
+
// SidebarLayoutWrapper - NOT exported (test workspace component only)
|
|
14
14
|
export { StandaloneLayoutWrapper } from "./components/standalone_layout_wrapper";
|
|
15
15
|
export { TwoColumnAuthLayout } from "./components/two_column_auth_layout";
|
|
16
16
|
export { UnauthorizedGuard } from "./components/unauthorized_guard";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roles_matrix.d.ts","sourceRoot":"","sources":["../../../../../src/components/layouts/user_management/components/roles_matrix.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"roles_matrix.d.ts","sourceRoot":"","sources":["../../../../../src/components/layouts/user_management/components/roles_matrix.tsx"],"names":[],"mappings":"AAgCA,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,KAAK,CAAC;QACX,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,OAAO,CAAC;QAClB,WAAW,EAAE,MAAM,EAAE,CAAC;KACvB,CAAC,CAAC;CACJ,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;IACzC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAGF;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,EAC1B,kBAAyB,EACzB,2BAAkC,EAClC,qBAA6B,EAC7B,gBAAuB,EACvB,OAAO,EACP,MAAM,EACN,QAAQ,EACR,eAAe,EACf,SAAS,GACV,EAAE,gBAAgB,2CAwhBlB"}
|
|
@@ -13,6 +13,7 @@ import { Label } from "../../../ui/label";
|
|
|
13
13
|
import { Plus, Loader2, CircleCheck, CircleX } from "lucide-react";
|
|
14
14
|
import { toast } from "sonner";
|
|
15
15
|
import { Avatar, AvatarImage, AvatarFallback } from "../../../ui/avatar";
|
|
16
|
+
import { useHazoAuthConfig } from "../../../../contexts/hazo_auth_provider";
|
|
16
17
|
// section: component
|
|
17
18
|
/**
|
|
18
19
|
* Roles matrix component - reusable internal component for roles-permissions matrix
|
|
@@ -23,6 +24,7 @@ import { Avatar, AvatarImage, AvatarFallback } from "../../../ui/avatar";
|
|
|
23
24
|
* @returns Roles matrix component
|
|
24
25
|
*/
|
|
25
26
|
export function RolesMatrix({ add_button_enabled = true, role_name_selection_enabled = true, permissions_read_only = false, show_save_cancel = true, user_id, onSave, onCancel, onRoleSelection, className, }) {
|
|
27
|
+
const { apiBasePath } = useHazoAuthConfig();
|
|
26
28
|
const [roles, setRoles] = useState([]);
|
|
27
29
|
const [originalRoles, setOriginalRoles] = useState([]);
|
|
28
30
|
const [permissions, setPermissions] = useState([]);
|
|
@@ -38,7 +40,7 @@ export function RolesMatrix({ add_button_enabled = true, role_name_selection_ena
|
|
|
38
40
|
setLoading(true);
|
|
39
41
|
try {
|
|
40
42
|
// Load roles and permissions
|
|
41
|
-
const roles_response = await fetch(
|
|
43
|
+
const roles_response = await fetch(`${apiBasePath}/user_management/roles`);
|
|
42
44
|
const roles_data = await roles_response.json();
|
|
43
45
|
if (!roles_data.success) {
|
|
44
46
|
toast.error("Failed to load roles and permissions");
|
|
@@ -63,7 +65,7 @@ export function RolesMatrix({ add_button_enabled = true, role_name_selection_ena
|
|
|
63
65
|
// If user_id is provided, load user info and user roles
|
|
64
66
|
if (user_id) {
|
|
65
67
|
// Load user info
|
|
66
|
-
const user_response = await fetch(
|
|
68
|
+
const user_response = await fetch(`${apiBasePath}/user_management/users?id=${user_id}`);
|
|
67
69
|
const user_data = await user_response.json();
|
|
68
70
|
if (user_data.success && Array.isArray(user_data.users) && user_data.users.length > 0) {
|
|
69
71
|
const user = user_data.users[0];
|
|
@@ -74,7 +76,7 @@ export function RolesMatrix({ add_button_enabled = true, role_name_selection_ena
|
|
|
74
76
|
});
|
|
75
77
|
}
|
|
76
78
|
// Load user roles
|
|
77
|
-
const user_roles_response = await fetch(
|
|
79
|
+
const user_roles_response = await fetch(`${apiBasePath}/user_management/users/roles?user_id=${user_id}`);
|
|
78
80
|
const user_roles_data = await user_roles_response.json();
|
|
79
81
|
if (user_roles_data.success && Array.isArray(user_roles_data.role_ids)) {
|
|
80
82
|
setUserRoleIds(user_roles_data.role_ids);
|
|
@@ -191,7 +193,7 @@ export function RolesMatrix({ add_button_enabled = true, role_name_selection_ena
|
|
|
191
193
|
.filter((role) => role.selected && role.role_id !== undefined)
|
|
192
194
|
.map((role) => role.role_id);
|
|
193
195
|
// Update user roles via API
|
|
194
|
-
const response = await fetch(
|
|
196
|
+
const response = await fetch(`${apiBasePath}/user_management/users/roles`, {
|
|
195
197
|
method: "PUT",
|
|
196
198
|
headers: {
|
|
197
199
|
"Content-Type": "application/json",
|
|
@@ -220,7 +222,7 @@ export function RolesMatrix({ add_button_enabled = true, role_name_selection_ena
|
|
|
220
222
|
onSave(roles_data);
|
|
221
223
|
}
|
|
222
224
|
// Save to API
|
|
223
|
-
const response = await fetch(
|
|
225
|
+
const response = await fetch(`${apiBasePath}/user_management/roles`, {
|
|
224
226
|
method: "PUT",
|
|
225
227
|
headers: {
|
|
226
228
|
"Content-Type": "application/json",
|
|
@@ -231,7 +233,7 @@ export function RolesMatrix({ add_button_enabled = true, role_name_selection_ena
|
|
|
231
233
|
if (data.success) {
|
|
232
234
|
toast.success("Roles and permissions saved successfully");
|
|
233
235
|
// Reload data to get updated role IDs
|
|
234
|
-
const reload_response = await fetch(
|
|
236
|
+
const reload_response = await fetch(`${apiBasePath}/user_management/roles`);
|
|
235
237
|
const reload_data = await reload_response.json();
|
|
236
238
|
if (reload_data.success) {
|
|
237
239
|
const updated_roles = reload_data.roles.map((role) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/layouts/user_management/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/layouts/user_management/index.tsx"],"names":[],"mappings":"AA6CA,MAAM,MAAM,yBAAyB,GAAG;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAsBF;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,SAAS,EAAE,EAAE,yBAAyB,2CAmsC5E"}
|
|
@@ -17,6 +17,7 @@ import { RolesMatrix } from "./components/roles_matrix";
|
|
|
17
17
|
import { UserX, KeyRound, Edit, Trash2, Loader2, CircleCheck, CircleX, Plus, UserPlus } from "lucide-react";
|
|
18
18
|
import { toast } from "sonner";
|
|
19
19
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../../ui/tooltip";
|
|
20
|
+
import { useHazoAuthConfig } from "../../../contexts/hazo_auth_provider";
|
|
20
21
|
// section: component
|
|
21
22
|
/**
|
|
22
23
|
* User Management layout component with three tabs
|
|
@@ -27,6 +28,7 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../../
|
|
|
27
28
|
* @returns User Management layout component
|
|
28
29
|
*/
|
|
29
30
|
export function UserManagementLayout({ className }) {
|
|
31
|
+
const { apiBasePath } = useHazoAuthConfig();
|
|
30
32
|
// Permission checks
|
|
31
33
|
const authResult = use_hazo_auth();
|
|
32
34
|
const hasUserManagementPermission = authResult.authenticated &&
|
|
@@ -64,7 +66,7 @@ export function UserManagementLayout({ className }) {
|
|
|
64
66
|
const loadUsers = useCallback(async () => {
|
|
65
67
|
setUsersLoading(true);
|
|
66
68
|
try {
|
|
67
|
-
const response = await fetch(
|
|
69
|
+
const response = await fetch(`${apiBasePath}/user_management/users`);
|
|
68
70
|
const data = await response.json();
|
|
69
71
|
if (data.success) {
|
|
70
72
|
setUsers(data.users);
|
|
@@ -97,7 +99,7 @@ export function UserManagementLayout({ className }) {
|
|
|
97
99
|
const loadPermissions = async () => {
|
|
98
100
|
setPermissionsLoading(true);
|
|
99
101
|
try {
|
|
100
|
-
const response = await fetch(
|
|
102
|
+
const response = await fetch(`${apiBasePath}/user_management/permissions`);
|
|
101
103
|
const data = await response.json();
|
|
102
104
|
if (data.success) {
|
|
103
105
|
const db_perms = data.db_permissions.map((p) => ({
|
|
@@ -133,7 +135,7 @@ export function UserManagementLayout({ className }) {
|
|
|
133
135
|
return;
|
|
134
136
|
setUsersActionLoading(true);
|
|
135
137
|
try {
|
|
136
|
-
const response = await fetch(
|
|
138
|
+
const response = await fetch(`${apiBasePath}/user_management/users`, {
|
|
137
139
|
method: "PATCH",
|
|
138
140
|
headers: {
|
|
139
141
|
"Content-Type": "application/json",
|
|
@@ -149,7 +151,7 @@ export function UserManagementLayout({ className }) {
|
|
|
149
151
|
setDeactivateDialogOpen(false);
|
|
150
152
|
setSelectedUser(null);
|
|
151
153
|
// Reload users
|
|
152
|
-
const reload_response = await fetch(
|
|
154
|
+
const reload_response = await fetch(`${apiBasePath}/user_management/users`);
|
|
153
155
|
const reload_data = await reload_response.json();
|
|
154
156
|
if (reload_data.success) {
|
|
155
157
|
setUsers(reload_data.users);
|
|
@@ -172,7 +174,7 @@ export function UserManagementLayout({ className }) {
|
|
|
172
174
|
return;
|
|
173
175
|
setUsersActionLoading(true);
|
|
174
176
|
try {
|
|
175
|
-
const response = await fetch(
|
|
177
|
+
const response = await fetch(`${apiBasePath}/user_management/users`, {
|
|
176
178
|
method: "POST",
|
|
177
179
|
headers: {
|
|
178
180
|
"Content-Type": "application/json",
|
|
@@ -203,7 +205,7 @@ export function UserManagementLayout({ className }) {
|
|
|
203
205
|
var _a, _b;
|
|
204
206
|
setMigrateLoading(true);
|
|
205
207
|
try {
|
|
206
|
-
const response = await fetch(
|
|
208
|
+
const response = await fetch(`${apiBasePath}/user_management/permissions?action=migrate`, {
|
|
207
209
|
method: "POST",
|
|
208
210
|
});
|
|
209
211
|
const data = await response.json();
|
|
@@ -224,7 +226,7 @@ export function UserManagementLayout({ className }) {
|
|
|
224
226
|
toast.info(`Skipped: ${data.skipped.join(", ")}`);
|
|
225
227
|
}
|
|
226
228
|
// Reload permissions
|
|
227
|
-
const reload_response = await fetch(
|
|
229
|
+
const reload_response = await fetch(`${apiBasePath}/user_management/permissions`);
|
|
228
230
|
const reload_data = await reload_response.json();
|
|
229
231
|
if (reload_data.success) {
|
|
230
232
|
const db_perms = reload_data.db_permissions.map((p) => ({
|
|
@@ -259,7 +261,7 @@ export function UserManagementLayout({ className }) {
|
|
|
259
261
|
return;
|
|
260
262
|
setPermissionsActionLoading(true);
|
|
261
263
|
try {
|
|
262
|
-
const response = await fetch(
|
|
264
|
+
const response = await fetch(`${apiBasePath}/user_management/permissions`, {
|
|
263
265
|
method: "PUT",
|
|
264
266
|
headers: {
|
|
265
267
|
"Content-Type": "application/json",
|
|
@@ -276,7 +278,7 @@ export function UserManagementLayout({ className }) {
|
|
|
276
278
|
setEditingPermission(null);
|
|
277
279
|
setEditDescription("");
|
|
278
280
|
// Reload permissions
|
|
279
|
-
const reload_response = await fetch(
|
|
281
|
+
const reload_response = await fetch(`${apiBasePath}/user_management/permissions`);
|
|
280
282
|
const reload_data = await reload_response.json();
|
|
281
283
|
if (reload_data.success) {
|
|
282
284
|
const db_perms = reload_data.db_permissions.map((p) => ({
|
|
@@ -313,7 +315,7 @@ export function UserManagementLayout({ className }) {
|
|
|
313
315
|
}
|
|
314
316
|
setPermissionsActionLoading(true);
|
|
315
317
|
try {
|
|
316
|
-
const response = await fetch(
|
|
318
|
+
const response = await fetch(`${apiBasePath}/user_management/permissions`, {
|
|
317
319
|
method: "POST",
|
|
318
320
|
headers: {
|
|
319
321
|
"Content-Type": "application/json",
|
|
@@ -330,7 +332,7 @@ export function UserManagementLayout({ className }) {
|
|
|
330
332
|
setNewPermissionName("");
|
|
331
333
|
setNewPermissionDescription("");
|
|
332
334
|
// Reload permissions
|
|
333
|
-
const reload_response = await fetch(
|
|
335
|
+
const reload_response = await fetch(`${apiBasePath}/user_management/permissions`);
|
|
334
336
|
const reload_data = await reload_response.json();
|
|
335
337
|
if (reload_data.success) {
|
|
336
338
|
const db_perms = reload_data.db_permissions.map((p) => ({
|
|
@@ -365,14 +367,14 @@ export function UserManagementLayout({ className }) {
|
|
|
365
367
|
return;
|
|
366
368
|
setPermissionsActionLoading(true);
|
|
367
369
|
try {
|
|
368
|
-
const response = await fetch(
|
|
370
|
+
const response = await fetch(`${apiBasePath}/user_management/permissions?permission_id=${permission.id}`, {
|
|
369
371
|
method: "DELETE",
|
|
370
372
|
});
|
|
371
373
|
const data = await response.json();
|
|
372
374
|
if (data.success) {
|
|
373
375
|
toast.success("Permission deleted successfully");
|
|
374
376
|
// Reload permissions
|
|
375
|
-
const reload_response = await fetch(
|
|
377
|
+
const reload_response = await fetch(`${apiBasePath}/user_management/permissions`);
|
|
376
378
|
const reload_data = await reload_response.json();
|
|
377
379
|
if (reload_data.success) {
|
|
378
380
|
const db_perms = reload_data.db_permissions.map((p) => ({
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime configuration for hazo_auth components
|
|
3
|
+
* Controls API paths and other runtime settings
|
|
4
|
+
*/
|
|
5
|
+
export type HazoAuthConfig = {
|
|
6
|
+
/**
|
|
7
|
+
* Base path for all hazo_auth API endpoints
|
|
8
|
+
* @default "/api/hazo_auth"
|
|
9
|
+
* @example "/api/v1/auth"
|
|
10
|
+
*/
|
|
11
|
+
apiBasePath: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Default configuration values
|
|
15
|
+
* Used when no provider is present or when values are not specified
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_HAZO_AUTH_CONFIG: HazoAuthConfig;
|
|
18
|
+
//# sourceMappingURL=hazo_auth_config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hazo_auth_config.d.ts","sourceRoot":"","sources":["../../src/contexts/hazo_auth_config.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,cAEtC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// file_description: Type definitions for HazoAuth runtime configuration
|
|
2
|
+
// This file defines the configuration structure for the HazoAuthProvider context
|
|
3
|
+
// section: types
|
|
4
|
+
/**
|
|
5
|
+
* Default configuration values
|
|
6
|
+
* Used when no provider is present or when values are not specified
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_HAZO_AUTH_CONFIG = {
|
|
9
|
+
apiBasePath: "/api/hazo_auth",
|
|
10
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type HazoAuthConfig } from "./hazo_auth_config";
|
|
3
|
+
/**
|
|
4
|
+
* Props for HazoAuthProvider component
|
|
5
|
+
*/
|
|
6
|
+
export type HazoAuthProviderProps = {
|
|
7
|
+
/**
|
|
8
|
+
* Base path for all hazo_auth API endpoints
|
|
9
|
+
* @default "/api/hazo_auth"
|
|
10
|
+
* @example "/api/v1/auth" - Custom API path
|
|
11
|
+
*/
|
|
12
|
+
apiBasePath?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Child components that will have access to the configuration
|
|
15
|
+
*/
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Context Provider for hazo_auth runtime configuration
|
|
20
|
+
*
|
|
21
|
+
* Wrap your app (or specific parts) with this provider to customize
|
|
22
|
+
* API paths and other runtime settings for all hazo_auth components.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* // In your root layout or app component
|
|
27
|
+
* import { HazoAuthProvider } from "hazo_auth/provider";
|
|
28
|
+
*
|
|
29
|
+
* export default function RootLayout({ children }) {
|
|
30
|
+
* return (
|
|
31
|
+
* <html>
|
|
32
|
+
* <body>
|
|
33
|
+
* <HazoAuthProvider apiBasePath="/api/v1/auth">
|
|
34
|
+
* {children}
|
|
35
|
+
* </HazoAuthProvider>
|
|
36
|
+
* </body>
|
|
37
|
+
* </html>
|
|
38
|
+
* );
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* // Using default values (no provider needed)
|
|
45
|
+
* // All components will use "/api/hazo_auth" as the base path
|
|
46
|
+
* export default function App() {
|
|
47
|
+
* return <LoginPage />;
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function HazoAuthProvider({ apiBasePath, children }: HazoAuthProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
52
|
+
/**
|
|
53
|
+
* Hook to access hazo_auth runtime configuration
|
|
54
|
+
*
|
|
55
|
+
* Returns the current configuration from the nearest HazoAuthProvider,
|
|
56
|
+
* or default values if no provider is present.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```tsx
|
|
60
|
+
* function MyComponent() {
|
|
61
|
+
* const { apiBasePath } = useHazoAuthConfig();
|
|
62
|
+
*
|
|
63
|
+
* const response = await fetch(`${apiBasePath}/login`, {
|
|
64
|
+
* method: "POST",
|
|
65
|
+
* body: JSON.stringify({ email, password }),
|
|
66
|
+
* });
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @returns Current HazoAuthConfig
|
|
71
|
+
*/
|
|
72
|
+
export declare function useHazoAuthConfig(): HazoAuthConfig;
|
|
73
|
+
//# sourceMappingURL=hazo_auth_provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hazo_auth_provider.d.ts","sourceRoot":"","sources":["../../src/contexts/hazo_auth_provider.tsx"],"names":[],"mappings":"AAMA,OAAc,EAAsC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClF,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAYnF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,WAAkD,EAClD,QAAQ,EACT,EAAE,qBAAqB,2CAcvB;AAID;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAMlD"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// file_description: React Context Provider for hazo_auth runtime configuration
|
|
2
|
+
// Provides global configuration for API paths and other runtime settings
|
|
3
|
+
// Must be used as a wrapper in consuming apps for customizing API endpoints
|
|
4
|
+
// section: imports
|
|
5
|
+
"use client";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
import { createContext, useContext, useMemo } from "react";
|
|
8
|
+
import { DEFAULT_HAZO_AUTH_CONFIG } from "./hazo_auth_config";
|
|
9
|
+
// section: context_definition
|
|
10
|
+
/**
|
|
11
|
+
* React Context for hazo_auth configuration
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
const HazoAuthConfigContext = createContext(DEFAULT_HAZO_AUTH_CONFIG);
|
|
15
|
+
// section: provider_component
|
|
16
|
+
/**
|
|
17
|
+
* Context Provider for hazo_auth runtime configuration
|
|
18
|
+
*
|
|
19
|
+
* Wrap your app (or specific parts) with this provider to customize
|
|
20
|
+
* API paths and other runtime settings for all hazo_auth components.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* // In your root layout or app component
|
|
25
|
+
* import { HazoAuthProvider } from "hazo_auth/provider";
|
|
26
|
+
*
|
|
27
|
+
* export default function RootLayout({ children }) {
|
|
28
|
+
* return (
|
|
29
|
+
* <html>
|
|
30
|
+
* <body>
|
|
31
|
+
* <HazoAuthProvider apiBasePath="/api/v1/auth">
|
|
32
|
+
* {children}
|
|
33
|
+
* </HazoAuthProvider>
|
|
34
|
+
* </body>
|
|
35
|
+
* </html>
|
|
36
|
+
* );
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* // Using default values (no provider needed)
|
|
43
|
+
* // All components will use "/api/hazo_auth" as the base path
|
|
44
|
+
* export default function App() {
|
|
45
|
+
* return <LoginPage />;
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function HazoAuthProvider({ apiBasePath = DEFAULT_HAZO_AUTH_CONFIG.apiBasePath, children }) {
|
|
50
|
+
// Memoize config to avoid unnecessary re-renders
|
|
51
|
+
const config = useMemo(() => ({
|
|
52
|
+
apiBasePath,
|
|
53
|
+
}), [apiBasePath]);
|
|
54
|
+
return (_jsx(HazoAuthConfigContext.Provider, { value: config, children: children }));
|
|
55
|
+
}
|
|
56
|
+
// section: hook
|
|
57
|
+
/**
|
|
58
|
+
* Hook to access hazo_auth runtime configuration
|
|
59
|
+
*
|
|
60
|
+
* Returns the current configuration from the nearest HazoAuthProvider,
|
|
61
|
+
* or default values if no provider is present.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```tsx
|
|
65
|
+
* function MyComponent() {
|
|
66
|
+
* const { apiBasePath } = useHazoAuthConfig();
|
|
67
|
+
*
|
|
68
|
+
* const response = await fetch(`${apiBasePath}/login`, {
|
|
69
|
+
* method: "POST",
|
|
70
|
+
* body: JSON.stringify({ email, password }),
|
|
71
|
+
* });
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @returns Current HazoAuthConfig
|
|
76
|
+
*/
|
|
77
|
+
export function useHazoAuthConfig() {
|
|
78
|
+
const context = useContext(HazoAuthConfigContext);
|
|
79
|
+
// Context will always have a value (either from provider or default)
|
|
80
|
+
// No need to check for undefined
|
|
81
|
+
return context;
|
|
82
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,oBAAoB,CAAC;AAGnC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAG5C,cAAc,oBAAoB,CAAC;AAGnC,cAAc,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// file_description: main entry point for hazo_auth package - exports all public APIs
|
|
2
|
+
// section: context_exports
|
|
3
|
+
export * from "./contexts/hazo_auth_provider";
|
|
4
|
+
export * from "./contexts/hazo_auth_config";
|
|
2
5
|
// section: component_exports
|
|
3
6
|
export * from "./components/index";
|
|
4
7
|
// section: lib_exports
|
|
@@ -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,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK1C,OAAO,KAAK,EAAE,cAAc,EAAgB,eAAe,EAAE,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,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK1C,OAAO,KAAK,EAAE,cAAc,EAAgB,eAAe,EAAE,MAAM,cAAc,CAAC;AAmLlF;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,cAAc,CAAC,CAmKzB"}
|
|
@@ -6,6 +6,7 @@ import { PermissionError } from "./auth_types";
|
|
|
6
6
|
import { get_auth_cache } from "./auth_cache";
|
|
7
7
|
import { get_rate_limiter } from "./auth_rate_limiter";
|
|
8
8
|
import { get_auth_utility_config } from "../auth_utility_config.server";
|
|
9
|
+
import { validate_session_token } from "../services/session_token_service";
|
|
9
10
|
// section: helpers
|
|
10
11
|
/**
|
|
11
12
|
* Gets client IP address from request
|
|
@@ -146,14 +147,41 @@ function get_friendly_error_message(missing_permissions, config) {
|
|
|
146
147
|
* @throws PermissionError if strict mode and permissions are missing
|
|
147
148
|
*/
|
|
148
149
|
export async function hazo_get_auth(request, options) {
|
|
149
|
-
var _a, _b;
|
|
150
|
+
var _a, _b, _c;
|
|
150
151
|
const logger = create_app_logger();
|
|
151
152
|
const config = get_auth_utility_config();
|
|
152
153
|
const cache = get_auth_cache(config.cache_max_users, config.cache_ttl_minutes, config.cache_max_age_minutes);
|
|
153
154
|
const rate_limiter = get_rate_limiter();
|
|
154
155
|
// Fast path: Check for authentication cookies
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
// Priority: 1. JWT session token (new), 2. Simple cookies (backward compatibility)
|
|
157
|
+
let user_id;
|
|
158
|
+
let user_email;
|
|
159
|
+
// Check for JWT session token first
|
|
160
|
+
const session_token = (_a = request.cookies.get("hazo_auth_session")) === null || _a === void 0 ? void 0 : _a.value;
|
|
161
|
+
if (session_token) {
|
|
162
|
+
try {
|
|
163
|
+
const token_result = await validate_session_token(session_token);
|
|
164
|
+
if (token_result.valid && token_result.user_id && token_result.email) {
|
|
165
|
+
user_id = token_result.user_id;
|
|
166
|
+
user_email = token_result.email;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (token_error) {
|
|
170
|
+
// If token validation fails, fall back to simple cookies
|
|
171
|
+
const token_error_message = token_error instanceof Error ? token_error.message : "Unknown error";
|
|
172
|
+
logger.debug("auth_utility_jwt_validation_failed", {
|
|
173
|
+
filename: get_filename(),
|
|
174
|
+
line_number: get_line_number(),
|
|
175
|
+
error: token_error_message,
|
|
176
|
+
note: "Falling back to simple cookie check",
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// Fall back to simple cookies if JWT not present or invalid (backward compatibility)
|
|
181
|
+
if (!user_id || !user_email) {
|
|
182
|
+
user_id = (_b = request.cookies.get("hazo_auth_user_id")) === null || _b === void 0 ? void 0 : _b.value;
|
|
183
|
+
user_email = (_c = request.cookies.get("hazo_auth_user_email")) === null || _c === void 0 ? void 0 : _c.value;
|
|
184
|
+
}
|
|
157
185
|
if (!user_id || !user_email) {
|
|
158
186
|
// Unauthenticated - check rate limit by IP
|
|
159
187
|
const client_ip = get_client_ip(request);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NextRequest } from "next/server";
|
|
2
|
+
export type ValidateSessionCookieResult = {
|
|
3
|
+
valid: boolean;
|
|
4
|
+
user_id?: string;
|
|
5
|
+
email?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Validates session cookie from NextRequest (Edge-compatible)
|
|
9
|
+
* Extracts hazo_auth_session cookie and validates JWT signature and expiry
|
|
10
|
+
* Works in Edge Runtime (Next.js proxy/middleware)
|
|
11
|
+
* @param request - NextRequest object
|
|
12
|
+
* @returns Validation result with user_id and email if valid
|
|
13
|
+
*/
|
|
14
|
+
export declare function validate_session_cookie(request: NextRequest): Promise<ValidateSessionCookieResult>;
|
|
15
|
+
//# sourceMappingURL=session_token_validator.edge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session_token_validator.edge.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/session_token_validator.edge.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,MAAM,MAAM,2BAA2B,GAAG;IACxC,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAsBF;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,2BAA2B,CAAC,CAwCtC"}
|