hazo_auth 1.0.5 → 1.2.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 +341 -0
- package/hazo_auth_config.example.ini +41 -0
- package/instrumentation.ts +2 -2
- package/package.json +2 -1
- package/scripts/init_users.ts +378 -0
- package/src/app/api/hazo_auth/login/route.ts +27 -1
- package/src/app/api/hazo_auth/register/route.ts +13 -10
- package/src/app/hazo_auth/forgot_password/page.tsx +3 -3
- package/src/app/hazo_auth/login/login_page_client.tsx +15 -0
- package/src/app/hazo_auth/login/page.tsx +16 -4
- package/src/app/hazo_auth/my_settings/page.tsx +3 -3
- package/src/app/hazo_auth/register/page.tsx +14 -4
- package/src/app/hazo_auth/register/register_page_client.tsx +9 -0
- package/src/app/hazo_auth/reset_password/page.tsx +3 -3
- package/src/app/hazo_auth/user_management/page.tsx +3 -3
- package/src/app/hazo_auth/verify_email/page.tsx +3 -3
- package/src/components/layouts/login/hooks/use_login_form.ts +13 -8
- package/src/components/layouts/login/index.tsx +28 -0
- package/src/components/layouts/register/hooks/use_register_form.ts +4 -1
- package/src/components/layouts/register/index.tsx +18 -0
- package/src/components/layouts/shared/components/auth_page_shell.tsx +36 -0
- package/src/components/layouts/shared/components/standalone_layout_wrapper.tsx +53 -0
- package/src/lib/config/config_loader.server.ts +20 -5
- package/src/lib/login_config.server.ts +25 -0
- package/src/lib/register_config.server.ts +17 -1
- package/src/lib/services/login_service.ts +19 -3
- package/src/lib/services/registration_service.ts +25 -4
- package/src/lib/services/user_profiles_service.ts +143 -0
- package/src/lib/services/user_update_service.ts +16 -3
- package/src/lib/ui_shell_config.server.ts +73 -0
- package/src/lib/utils/error_sanitizer.ts +75 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// file_description: render the reset password page shell and mount the reset password layout component within sidebar
|
|
2
2
|
// section: imports
|
|
3
|
-
import {
|
|
3
|
+
import { AuthPageShell } from "../../../components/layouts/shared/components/auth_page_shell";
|
|
4
4
|
import { ResetPasswordPageClient } from "./reset_password_page_client";
|
|
5
5
|
import { get_reset_password_config } from "../../../lib/reset_password_config.server";
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ export default function reset_password_page() {
|
|
|
10
10
|
const resetPasswordConfig = get_reset_password_config();
|
|
11
11
|
|
|
12
12
|
return (
|
|
13
|
-
<
|
|
13
|
+
<AuthPageShell>
|
|
14
14
|
<ResetPasswordPageClient
|
|
15
15
|
errorMessage={resetPasswordConfig.errorMessage}
|
|
16
16
|
successMessage={resetPasswordConfig.successMessage}
|
|
@@ -23,7 +23,7 @@ export default function reset_password_page() {
|
|
|
23
23
|
returnHomePath={resetPasswordConfig.returnHomePath}
|
|
24
24
|
passwordRequirements={resetPasswordConfig.passwordRequirements}
|
|
25
25
|
/>
|
|
26
|
-
</
|
|
26
|
+
</AuthPageShell>
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// file_description: render the user management page shell and mount the user management layout component within sidebar
|
|
2
2
|
// section: imports
|
|
3
|
-
import {
|
|
3
|
+
import { AuthPageShell } from "../../../components/layouts/shared/components/auth_page_shell";
|
|
4
4
|
import { UserManagementPageClient } from "./user_management_page_client";
|
|
5
5
|
|
|
6
6
|
// section: component
|
|
7
7
|
export default function user_management_page() {
|
|
8
8
|
return (
|
|
9
|
-
<
|
|
9
|
+
<AuthPageShell>
|
|
10
10
|
<UserManagementPageClient />
|
|
11
|
-
</
|
|
11
|
+
</AuthPageShell>
|
|
12
12
|
);
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// file_description: render the email verification page shell and mount the email verification layout component within sidebar
|
|
2
2
|
// section: imports
|
|
3
|
-
import {
|
|
3
|
+
import { AuthPageShell } from "../../../components/layouts/shared/components/auth_page_shell";
|
|
4
4
|
import { VerifyEmailPageClient } from "./verify_email_page_client";
|
|
5
5
|
import { get_email_verification_config } from "../../../lib/email_verification_config.server";
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ export default function verify_email_page() {
|
|
|
10
10
|
const emailVerificationConfig = get_email_verification_config();
|
|
11
11
|
|
|
12
12
|
return (
|
|
13
|
-
<
|
|
13
|
+
<AuthPageShell>
|
|
14
14
|
<VerifyEmailPageClient
|
|
15
15
|
alreadyLoggedInMessage={emailVerificationConfig.alreadyLoggedInMessage}
|
|
16
16
|
showLogoutButton={emailVerificationConfig.showLogoutButton}
|
|
@@ -18,7 +18,7 @@ export default function verify_email_page() {
|
|
|
18
18
|
returnHomeButtonLabel={emailVerificationConfig.returnHomeButtonLabel}
|
|
19
19
|
returnHomePath={emailVerificationConfig.returnHomePath}
|
|
20
20
|
/>
|
|
21
|
-
</
|
|
21
|
+
</AuthPageShell>
|
|
22
22
|
);
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -25,6 +25,7 @@ export type UseLoginFormParams<TClient = unknown> = {
|
|
|
25
25
|
};
|
|
26
26
|
redirectRoute?: string;
|
|
27
27
|
successMessage?: string;
|
|
28
|
+
urlOnLogon?: string;
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
export type UseLoginFormResult = {
|
|
@@ -62,6 +63,7 @@ export const use_login_form = <TClient,>({
|
|
|
62
63
|
logger,
|
|
63
64
|
redirectRoute,
|
|
64
65
|
successMessage = "Successfully logged in",
|
|
66
|
+
urlOnLogon,
|
|
65
67
|
}: UseLoginFormParams<TClient>): UseLoginFormResult => {
|
|
66
68
|
const router = useRouter();
|
|
67
69
|
const [values, setValues] = useState<LoginFormValues>(buildInitialValues);
|
|
@@ -87,10 +89,9 @@ export const use_login_form = <TClient,>({
|
|
|
87
89
|
}, []);
|
|
88
90
|
|
|
89
91
|
const isSubmitDisabled = useMemo(() => {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}, [errors, values]);
|
|
92
|
+
const allFieldsEmpty = Object.values(values).every((fieldValue) => fieldValue.trim() === "");
|
|
93
|
+
return allFieldsEmpty;
|
|
94
|
+
}, [values]);
|
|
94
95
|
|
|
95
96
|
const togglePasswordVisibility = useCallback(() => {
|
|
96
97
|
setPasswordVisibility((previous) => ({
|
|
@@ -189,6 +190,7 @@ export const use_login_form = <TClient,>({
|
|
|
189
190
|
body: JSON.stringify({
|
|
190
191
|
email,
|
|
191
192
|
password,
|
|
193
|
+
url_on_logon: urlOnLogon,
|
|
192
194
|
}),
|
|
193
195
|
});
|
|
194
196
|
|
|
@@ -230,9 +232,12 @@ export const use_login_form = <TClient,>({
|
|
|
230
232
|
// Refresh the page to update authentication state (cookies are set server-side)
|
|
231
233
|
router.refresh();
|
|
232
234
|
|
|
233
|
-
//
|
|
234
|
-
|
|
235
|
-
|
|
235
|
+
// Use redirectUrl from server response if available, otherwise fall back to redirectRoute prop
|
|
236
|
+
// The server logic already prioritizes: query param > stored DB value > config > default "/"
|
|
237
|
+
const finalRedirectUrl = data.redirectUrl || redirectRoute;
|
|
238
|
+
|
|
239
|
+
if (finalRedirectUrl) {
|
|
240
|
+
router.push(finalRedirectUrl);
|
|
236
241
|
} else {
|
|
237
242
|
// Otherwise, show success message
|
|
238
243
|
setIsSuccess(true);
|
|
@@ -251,7 +256,7 @@ export const use_login_form = <TClient,>({
|
|
|
251
256
|
setIsSuccess(false);
|
|
252
257
|
}
|
|
253
258
|
},
|
|
254
|
-
[values, clientIp, log_login_attempt, redirectRoute, router],
|
|
259
|
+
[values, clientIp, log_login_attempt, redirectRoute, router, urlOnLogon],
|
|
255
260
|
);
|
|
256
261
|
|
|
257
262
|
const handleCancel = useCallback(() => {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"use client";
|
|
4
4
|
|
|
5
5
|
// section: imports
|
|
6
|
+
import Link from "next/link";
|
|
6
7
|
import { Input } from "../../ui/input";
|
|
7
8
|
import { PasswordField } from "../shared/components/password_field";
|
|
8
9
|
import { FormFieldWrapper } from "../shared/components/form_field_wrapper";
|
|
@@ -50,6 +51,11 @@ export type LoginLayoutProps<TClient = unknown> = {
|
|
|
50
51
|
showReturnHomeButton?: boolean;
|
|
51
52
|
returnHomeButtonLabel?: string;
|
|
52
53
|
returnHomePath?: string;
|
|
54
|
+
forgot_password_path?: string;
|
|
55
|
+
forgot_password_label?: string;
|
|
56
|
+
create_account_path?: string;
|
|
57
|
+
create_account_label?: string;
|
|
58
|
+
urlOnLogon?: string;
|
|
53
59
|
};
|
|
54
60
|
|
|
55
61
|
const ORDERED_FIELDS: LoginFieldId[] = [
|
|
@@ -76,6 +82,11 @@ export default function login_layout<TClient>({
|
|
|
76
82
|
showReturnHomeButton = false,
|
|
77
83
|
returnHomeButtonLabel = "Return home",
|
|
78
84
|
returnHomePath = "/",
|
|
85
|
+
forgot_password_path = "/hazo_auth/forgot_password",
|
|
86
|
+
forgot_password_label = "Forgot password?",
|
|
87
|
+
create_account_path = "/hazo_auth/register",
|
|
88
|
+
create_account_label = "Create account",
|
|
89
|
+
urlOnLogon,
|
|
79
90
|
}: LoginLayoutProps<TClient>) {
|
|
80
91
|
const fieldDefinitions = createLoginFieldDefinitions(field_overrides);
|
|
81
92
|
const resolvedLabels = resolveLoginLabels(labels);
|
|
@@ -86,6 +97,7 @@ export default function login_layout<TClient>({
|
|
|
86
97
|
logger,
|
|
87
98
|
redirectRoute,
|
|
88
99
|
successMessage,
|
|
100
|
+
urlOnLogon: urlOnLogon,
|
|
89
101
|
});
|
|
90
102
|
|
|
91
103
|
const renderFields = (formState: UseLoginFormResult) => {
|
|
@@ -214,6 +226,22 @@ export default function login_layout<TClient>({
|
|
|
214
226
|
submitAriaLabel="Submit login form"
|
|
215
227
|
cancelAriaLabel="Cancel login form"
|
|
216
228
|
/>
|
|
229
|
+
<div className="cls_login_layout_support_links flex flex-col gap-1 text-sm text-muted-foreground">
|
|
230
|
+
<Link
|
|
231
|
+
href={forgot_password_path}
|
|
232
|
+
className="cls_login_layout_forgot_password_link text-primary underline-offset-4 hover:underline"
|
|
233
|
+
aria-label="Go to forgot password page"
|
|
234
|
+
>
|
|
235
|
+
{forgot_password_label}
|
|
236
|
+
</Link>
|
|
237
|
+
<Link
|
|
238
|
+
href={create_account_path}
|
|
239
|
+
className="cls_login_layout_create_account_link text-primary underline-offset-4 hover:underline"
|
|
240
|
+
aria-label="Go to create account page"
|
|
241
|
+
>
|
|
242
|
+
{create_account_label}
|
|
243
|
+
</Link>
|
|
244
|
+
</div>
|
|
217
245
|
</form>
|
|
218
246
|
</>
|
|
219
247
|
}
|
|
@@ -28,6 +28,7 @@ export type UseRegisterFormParams<TClient = unknown> = {
|
|
|
28
28
|
passwordRequirements: PasswordRequirementOptions;
|
|
29
29
|
passwordRequirementOverrides?: PasswordRequirementOverrides;
|
|
30
30
|
dataClient: LayoutDataClient<TClient>;
|
|
31
|
+
urlOnLogon?: string;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
export type UseRegisterFormResult = {
|
|
@@ -58,6 +59,7 @@ export const use_register_form = <TClient,>({
|
|
|
58
59
|
showNameField,
|
|
59
60
|
passwordRequirements,
|
|
60
61
|
dataClient,
|
|
62
|
+
urlOnLogon,
|
|
61
63
|
}: UseRegisterFormParams<TClient>): UseRegisterFormResult => {
|
|
62
64
|
const [values, setValues] = useState<RegisterFormValues>(buildInitialValues);
|
|
63
65
|
const [errors, setErrors] = useState<RegisterFormErrors>({});
|
|
@@ -203,6 +205,7 @@ export const use_register_form = <TClient,>({
|
|
|
203
205
|
name: values[REGISTER_FIELD_IDS.NAME] || undefined,
|
|
204
206
|
email: values[REGISTER_FIELD_IDS.EMAIL],
|
|
205
207
|
password: values[REGISTER_FIELD_IDS.PASSWORD],
|
|
208
|
+
url_on_logon: urlOnLogon,
|
|
206
209
|
}),
|
|
207
210
|
});
|
|
208
211
|
|
|
@@ -242,7 +245,7 @@ export const use_register_form = <TClient,>({
|
|
|
242
245
|
setIsSubmitting(false);
|
|
243
246
|
}
|
|
244
247
|
},
|
|
245
|
-
[values, passwordRequirements, dataClient],
|
|
248
|
+
[values, passwordRequirements, dataClient, urlOnLogon],
|
|
246
249
|
);
|
|
247
250
|
|
|
248
251
|
const handleCancel = useCallback(() => {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"use client";
|
|
4
4
|
|
|
5
5
|
// section: imports
|
|
6
|
+
import Link from "next/link";
|
|
6
7
|
import { Input } from "../../ui/input";
|
|
7
8
|
import { PasswordField } from "../shared/components/password_field";
|
|
8
9
|
import { FormFieldWrapper } from "../shared/components/form_field_wrapper";
|
|
@@ -45,6 +46,9 @@ export type RegisterLayoutProps<TClient = unknown> = {
|
|
|
45
46
|
showReturnHomeButton?: boolean;
|
|
46
47
|
returnHomeButtonLabel?: string;
|
|
47
48
|
returnHomePath?: string;
|
|
49
|
+
signInPath?: string;
|
|
50
|
+
signInLabel?: string;
|
|
51
|
+
urlOnLogon?: string;
|
|
48
52
|
};
|
|
49
53
|
|
|
50
54
|
const ORDERED_FIELDS: RegisterFieldId[] = [
|
|
@@ -72,6 +76,9 @@ export default function register_layout<TClient>({
|
|
|
72
76
|
showReturnHomeButton = false,
|
|
73
77
|
returnHomeButtonLabel = "Return home",
|
|
74
78
|
returnHomePath = "/",
|
|
79
|
+
signInPath = "/hazo_auth/login",
|
|
80
|
+
signInLabel = "Sign in",
|
|
81
|
+
urlOnLogon,
|
|
75
82
|
}: RegisterLayoutProps<TClient>) {
|
|
76
83
|
const fieldDefinitions = createRegisterFieldDefinitions(field_overrides);
|
|
77
84
|
const resolvedLabels = resolveRegisterLabels(labels);
|
|
@@ -84,6 +91,7 @@ export default function register_layout<TClient>({
|
|
|
84
91
|
showNameField: show_name_field,
|
|
85
92
|
passwordRequirements: resolvedPasswordRequirements,
|
|
86
93
|
dataClient: data_client,
|
|
94
|
+
urlOnLogon: urlOnLogon,
|
|
87
95
|
});
|
|
88
96
|
|
|
89
97
|
const renderFields = (formState: UseRegisterFormResult) => {
|
|
@@ -193,6 +201,16 @@ export default function register_layout<TClient>({
|
|
|
193
201
|
submitAriaLabel="Submit registration form"
|
|
194
202
|
cancelAriaLabel="Cancel registration form"
|
|
195
203
|
/>
|
|
204
|
+
<div className="cls_register_layout_sign_in_link flex items-center justify-center gap-1 text-sm text-muted-foreground">
|
|
205
|
+
<span>Already have an account?</span>
|
|
206
|
+
<Link
|
|
207
|
+
href={signInPath}
|
|
208
|
+
className="cls_register_layout_sign_in_link_text text-primary underline-offset-4 hover:underline"
|
|
209
|
+
aria-label="Go to sign in page"
|
|
210
|
+
>
|
|
211
|
+
{signInLabel}
|
|
212
|
+
</Link>
|
|
213
|
+
</div>
|
|
196
214
|
{form.isSubmitting && (
|
|
197
215
|
<div className="cls_register_submitting_indicator text-sm text-slate-600 text-center">
|
|
198
216
|
Registering...
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// file_description: server component that chooses between sidebar shell and standalone shell
|
|
2
|
+
// section: imports
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
import { SidebarLayoutWrapper } from "./sidebar_layout_wrapper";
|
|
5
|
+
import { StandaloneLayoutWrapper } from "./standalone_layout_wrapper";
|
|
6
|
+
import { get_ui_shell_config } from "../../../../lib/ui_shell_config.server";
|
|
7
|
+
|
|
8
|
+
// section: types
|
|
9
|
+
type AuthPageShellProps = {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// section: component
|
|
14
|
+
export function AuthPageShell({ children }: AuthPageShellProps) {
|
|
15
|
+
const uiShellConfig = get_ui_shell_config();
|
|
16
|
+
|
|
17
|
+
if (uiShellConfig.layout_mode === "standalone") {
|
|
18
|
+
return (
|
|
19
|
+
<StandaloneLayoutWrapper
|
|
20
|
+
heading={uiShellConfig.standalone_heading}
|
|
21
|
+
description={uiShellConfig.standalone_description}
|
|
22
|
+
wrapperClassName={uiShellConfig.standalone_wrapper_class}
|
|
23
|
+
contentClassName={uiShellConfig.standalone_content_class}
|
|
24
|
+
showHeading={uiShellConfig.standalone_show_heading}
|
|
25
|
+
showDescription={uiShellConfig.standalone_show_description}
|
|
26
|
+
>
|
|
27
|
+
{children}
|
|
28
|
+
</StandaloneLayoutWrapper>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return <SidebarLayoutWrapper>{children}</SidebarLayoutWrapper>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// file_description: renders a simple full-width shell without the developer sidebar
|
|
2
|
+
// section: client_directive
|
|
3
|
+
"use client";
|
|
4
|
+
|
|
5
|
+
// section: imports
|
|
6
|
+
import { cn } from "../../../../lib/utils";
|
|
7
|
+
|
|
8
|
+
// section: types
|
|
9
|
+
export type StandaloneLayoutWrapperProps = {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
heading?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
wrapperClassName?: string;
|
|
14
|
+
contentClassName?: string;
|
|
15
|
+
showHeading?: boolean;
|
|
16
|
+
showDescription?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// section: component
|
|
20
|
+
export function StandaloneLayoutWrapper({
|
|
21
|
+
children,
|
|
22
|
+
heading = "hazo auth",
|
|
23
|
+
description = "Drop-in authentication flows that inherit your existing theme.",
|
|
24
|
+
wrapperClassName,
|
|
25
|
+
contentClassName,
|
|
26
|
+
showHeading = true,
|
|
27
|
+
showDescription = true,
|
|
28
|
+
}: StandaloneLayoutWrapperProps) {
|
|
29
|
+
return (
|
|
30
|
+
<div className={cn("cls_standalone_layout_wrapper min-h-screen w-full bg-background", wrapperClassName)}>
|
|
31
|
+
<div className={cn("cls_standalone_layout_content mx-auto flex w-full max-w-5xl flex-col gap-8 p-6", contentClassName)}>
|
|
32
|
+
{(showHeading || showDescription) && (
|
|
33
|
+
<div className="cls_standalone_layout_header text-center">
|
|
34
|
+
{showHeading && (
|
|
35
|
+
<h1 className="cls_standalone_layout_title text-2xl font-semibold tracking-tight text-foreground">
|
|
36
|
+
{heading}
|
|
37
|
+
</h1>
|
|
38
|
+
)}
|
|
39
|
+
{showDescription && (
|
|
40
|
+
<p className="cls_standalone_layout_description mt-2 text-sm text-muted-foreground">
|
|
41
|
+
{description}
|
|
42
|
+
</p>
|
|
43
|
+
)}
|
|
44
|
+
</div>
|
|
45
|
+
)}
|
|
46
|
+
<div className="cls_standalone_layout_body">{children}</div>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
@@ -71,7 +71,12 @@ export function get_config_value(
|
|
|
71
71
|
file_path?: string,
|
|
72
72
|
): string {
|
|
73
73
|
const section = read_config_section(section_name, file_path);
|
|
74
|
-
|
|
74
|
+
// Optional chaining on section and section[key]
|
|
75
|
+
// If section is undefined, or key is undefined, fall back to default
|
|
76
|
+
if (!section || section[key] === undefined) {
|
|
77
|
+
return default_value;
|
|
78
|
+
}
|
|
79
|
+
return section[key].trim() || default_value;
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
/**
|
|
@@ -89,12 +94,12 @@ export function get_config_boolean(
|
|
|
89
94
|
file_path?: string,
|
|
90
95
|
): boolean {
|
|
91
96
|
const section = read_config_section(section_name, file_path);
|
|
92
|
-
const value = section?.[key]?.trim().toLowerCase();
|
|
93
97
|
|
|
94
|
-
if (
|
|
98
|
+
if (!section || section[key] === undefined) {
|
|
95
99
|
return default_value;
|
|
96
100
|
}
|
|
97
101
|
|
|
102
|
+
const value = section[key].trim().toLowerCase();
|
|
98
103
|
return value !== "false" && value !== "0" && value !== "";
|
|
99
104
|
}
|
|
100
105
|
|
|
@@ -113,7 +118,12 @@ export function get_config_number(
|
|
|
113
118
|
file_path?: string,
|
|
114
119
|
): number {
|
|
115
120
|
const section = read_config_section(section_name, file_path);
|
|
116
|
-
|
|
121
|
+
|
|
122
|
+
if (!section || section[key] === undefined) {
|
|
123
|
+
return default_value;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const value = section[key].trim();
|
|
117
127
|
|
|
118
128
|
if (!value) {
|
|
119
129
|
return default_value;
|
|
@@ -138,7 +148,12 @@ export function get_config_array(
|
|
|
138
148
|
file_path?: string,
|
|
139
149
|
): string[] {
|
|
140
150
|
const section = read_config_section(section_name, file_path);
|
|
141
|
-
|
|
151
|
+
|
|
152
|
+
if (!section || section[key] === undefined) {
|
|
153
|
+
return default_value;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const value = section[key].trim();
|
|
142
157
|
|
|
143
158
|
if (!value) {
|
|
144
159
|
return default_value;
|
|
@@ -12,6 +12,10 @@ export type LoginConfig = {
|
|
|
12
12
|
showReturnHomeButton: boolean;
|
|
13
13
|
returnHomeButtonLabel: string;
|
|
14
14
|
returnHomePath: string;
|
|
15
|
+
forgotPasswordPath: string;
|
|
16
|
+
forgotPasswordLabel: string;
|
|
17
|
+
createAccountPath: string;
|
|
18
|
+
createAccountLabel: string;
|
|
15
19
|
};
|
|
16
20
|
|
|
17
21
|
// section: helpers
|
|
@@ -30,6 +34,23 @@ export function get_login_config(): LoginConfig {
|
|
|
30
34
|
// Read success message (defaults to "Successfully logged in")
|
|
31
35
|
const successMessage = get_config_value(section, "success_message", "Successfully logged in");
|
|
32
36
|
|
|
37
|
+
const forgotPasswordPath = get_config_value(
|
|
38
|
+
section,
|
|
39
|
+
"forgot_password_path",
|
|
40
|
+
"/hazo_auth/forgot_password"
|
|
41
|
+
);
|
|
42
|
+
const forgotPasswordLabel = get_config_value(
|
|
43
|
+
section,
|
|
44
|
+
"forgot_password_label",
|
|
45
|
+
"Forgot password?"
|
|
46
|
+
);
|
|
47
|
+
const createAccountPath = get_config_value(section, "create_account_path", "/hazo_auth/register");
|
|
48
|
+
const createAccountLabel = get_config_value(
|
|
49
|
+
section,
|
|
50
|
+
"create_account_label",
|
|
51
|
+
"Create account"
|
|
52
|
+
);
|
|
53
|
+
|
|
33
54
|
// Get shared already logged in config
|
|
34
55
|
const alreadyLoggedInConfig = get_already_logged_in_config();
|
|
35
56
|
|
|
@@ -41,6 +62,10 @@ export function get_login_config(): LoginConfig {
|
|
|
41
62
|
showReturnHomeButton: alreadyLoggedInConfig.showReturnHomeButton,
|
|
42
63
|
returnHomeButtonLabel: alreadyLoggedInConfig.returnHomeButtonLabel,
|
|
43
64
|
returnHomePath: alreadyLoggedInConfig.returnHomePath,
|
|
65
|
+
forgotPasswordPath,
|
|
66
|
+
forgotPasswordLabel,
|
|
67
|
+
createAccountPath,
|
|
68
|
+
createAccountLabel,
|
|
44
69
|
};
|
|
45
70
|
}
|
|
46
71
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// file_description: server-only helper to read register layout configuration from hazo_auth_config.ini
|
|
2
2
|
// section: imports
|
|
3
|
-
import { get_config_boolean, read_config_section } from "./config/config_loader.server";
|
|
3
|
+
import { get_config_boolean, get_config_value, read_config_section } from "./config/config_loader.server";
|
|
4
4
|
import { get_password_requirements_config } from "./password_requirements_config.server";
|
|
5
5
|
import { get_already_logged_in_config } from "./already_logged_in_config.server";
|
|
6
6
|
import { get_user_fields_config } from "./user_fields_config.server";
|
|
@@ -20,6 +20,8 @@ export type RegisterConfig = {
|
|
|
20
20
|
showReturnHomeButton: boolean;
|
|
21
21
|
returnHomeButtonLabel: string;
|
|
22
22
|
returnHomePath: string;
|
|
23
|
+
signInPath: string;
|
|
24
|
+
signInLabel: string;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
// section: helpers
|
|
@@ -44,6 +46,18 @@ export function get_register_config(): RegisterConfig {
|
|
|
44
46
|
// Get shared already logged in config
|
|
45
47
|
const alreadyLoggedInConfig = get_already_logged_in_config();
|
|
46
48
|
|
|
49
|
+
// Read sign in link configuration
|
|
50
|
+
const signInPath = get_config_value(
|
|
51
|
+
"hazo_auth__register_layout",
|
|
52
|
+
"sign_in_path",
|
|
53
|
+
"/hazo_auth/login"
|
|
54
|
+
);
|
|
55
|
+
const signInLabel = get_config_value(
|
|
56
|
+
"hazo_auth__register_layout",
|
|
57
|
+
"sign_in_label",
|
|
58
|
+
"Sign in"
|
|
59
|
+
);
|
|
60
|
+
|
|
47
61
|
return {
|
|
48
62
|
showNameField,
|
|
49
63
|
passwordRequirements,
|
|
@@ -52,6 +66,8 @@ export function get_register_config(): RegisterConfig {
|
|
|
52
66
|
showReturnHomeButton: alreadyLoggedInConfig.showReturnHomeButton,
|
|
53
67
|
returnHomeButtonLabel: alreadyLoggedInConfig.returnHomeButtonLabel,
|
|
54
68
|
returnHomePath: alreadyLoggedInConfig.returnHomePath,
|
|
69
|
+
signInPath,
|
|
70
|
+
signInLabel,
|
|
55
71
|
};
|
|
56
72
|
}
|
|
57
73
|
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
import type { HazoConnectAdapter } from "hazo_connect";
|
|
4
4
|
import { createCrudService } from "hazo_connect/server";
|
|
5
5
|
import argon2 from "argon2";
|
|
6
|
+
import { create_app_logger } from "../app_logger";
|
|
7
|
+
import { sanitize_error_for_user } from "../utils/error_sanitizer";
|
|
8
|
+
import { get_filename, get_line_number } from "../utils/api_route_helpers";
|
|
6
9
|
|
|
7
10
|
// section: types
|
|
8
11
|
export type LoginData = {
|
|
@@ -15,6 +18,7 @@ export type LoginResult = {
|
|
|
15
18
|
user_id?: string;
|
|
16
19
|
error?: string;
|
|
17
20
|
email_not_verified?: boolean;
|
|
21
|
+
stored_url_on_logon?: string | null;
|
|
18
22
|
};
|
|
19
23
|
|
|
20
24
|
// section: helpers
|
|
@@ -98,20 +102,32 @@ export async function authenticate_user(
|
|
|
98
102
|
last_logon: now,
|
|
99
103
|
login_attempts: 0,
|
|
100
104
|
changed_at: now,
|
|
105
|
+
url_on_logon: null, // Clear the stored redirect URL after successful login
|
|
101
106
|
}
|
|
102
107
|
);
|
|
103
108
|
|
|
104
109
|
return {
|
|
105
110
|
success: true,
|
|
106
111
|
user_id: user.id as string,
|
|
112
|
+
stored_url_on_logon: user.url_on_logon as string | null | undefined,
|
|
107
113
|
};
|
|
108
114
|
} catch (error) {
|
|
109
|
-
const
|
|
110
|
-
|
|
115
|
+
const logger = create_app_logger();
|
|
116
|
+
const user_friendly_error = sanitize_error_for_user(error, {
|
|
117
|
+
logToConsole: true,
|
|
118
|
+
logToLogger: true,
|
|
119
|
+
logger,
|
|
120
|
+
context: {
|
|
121
|
+
filename: "login_service.ts",
|
|
122
|
+
line_number: get_line_number(),
|
|
123
|
+
email: data.email,
|
|
124
|
+
operation: "authenticate_user",
|
|
125
|
+
},
|
|
126
|
+
});
|
|
111
127
|
|
|
112
128
|
return {
|
|
113
129
|
success: false,
|
|
114
|
-
error:
|
|
130
|
+
error: user_friendly_error,
|
|
115
131
|
};
|
|
116
132
|
}
|
|
117
133
|
}
|
|
@@ -10,12 +10,15 @@ import { get_profile_picture_config } from "../profile_picture_config.server";
|
|
|
10
10
|
import { map_ui_source_to_db } from "./profile_picture_source_mapper";
|
|
11
11
|
import { create_app_logger } from "../app_logger";
|
|
12
12
|
import { send_template_email } from "./email_service";
|
|
13
|
+
import { sanitize_error_for_user } from "../utils/error_sanitizer";
|
|
14
|
+
import { get_filename, get_line_number } from "../utils/api_route_helpers";
|
|
13
15
|
|
|
14
16
|
// section: types
|
|
15
17
|
export type RegistrationData = {
|
|
16
18
|
email: string;
|
|
17
19
|
password: string;
|
|
18
20
|
name?: string;
|
|
21
|
+
url_on_logon?: string;
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
export type RegistrationResult = {
|
|
@@ -36,7 +39,7 @@ export async function register_user(
|
|
|
36
39
|
data: RegistrationData,
|
|
37
40
|
): Promise<RegistrationResult> {
|
|
38
41
|
try {
|
|
39
|
-
const { email, password, name } = data;
|
|
42
|
+
const { email, password, name, url_on_logon } = data;
|
|
40
43
|
|
|
41
44
|
// Create CRUD service for hazo_users table
|
|
42
45
|
const users_service = createCrudService(adapter, "hazo_users");
|
|
@@ -77,6 +80,14 @@ export async function register_user(
|
|
|
77
80
|
insert_data.name = name;
|
|
78
81
|
}
|
|
79
82
|
|
|
83
|
+
// Validate and include url_on_logon if provided
|
|
84
|
+
if (url_on_logon) {
|
|
85
|
+
// Ensure it's a relative path starting with / but not //
|
|
86
|
+
if (url_on_logon.startsWith("/") && !url_on_logon.startsWith("//")) {
|
|
87
|
+
insert_data.url_on_logon = url_on_logon;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
80
91
|
// Set default profile picture if enabled
|
|
81
92
|
const profile_picture_config = get_profile_picture_config();
|
|
82
93
|
if (profile_picture_config.user_photo_default) {
|
|
@@ -151,12 +162,22 @@ export async function register_user(
|
|
|
151
162
|
user_id,
|
|
152
163
|
};
|
|
153
164
|
} catch (error) {
|
|
154
|
-
const
|
|
155
|
-
|
|
165
|
+
const logger = create_app_logger();
|
|
166
|
+
const user_friendly_error = sanitize_error_for_user(error, {
|
|
167
|
+
logToConsole: true,
|
|
168
|
+
logToLogger: true,
|
|
169
|
+
logger,
|
|
170
|
+
context: {
|
|
171
|
+
filename: "registration_service.ts",
|
|
172
|
+
line_number: get_line_number(),
|
|
173
|
+
email: data.email,
|
|
174
|
+
operation: "register_user",
|
|
175
|
+
},
|
|
176
|
+
});
|
|
156
177
|
|
|
157
178
|
return {
|
|
158
179
|
success: false,
|
|
159
|
-
error:
|
|
180
|
+
error: user_friendly_error,
|
|
160
181
|
};
|
|
161
182
|
}
|
|
162
183
|
}
|