hazo_auth 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +48 -0
- package/components.json +22 -0
- package/hazo_auth_config.example.ini +414 -0
- package/hazo_notify_config.example.ini +159 -0
- package/instrumentation.ts +32 -0
- package/migrations/001_add_token_type_to_refresh_tokens.sql +14 -0
- package/migrations/002_add_name_to_hazo_users.sql +7 -0
- package/next.config.mjs +55 -0
- package/package.json +114 -0
- package/postcss.config.mjs +8 -0
- package/public/file.svg +1 -0
- package/public/globe.svg +1 -0
- package/public/next.svg +1 -0
- package/public/vercel.svg +1 -0
- package/public/window.svg +1 -0
- package/scripts/apply_migration.ts +118 -0
- package/src/app/api/auth/change_password/route.ts +109 -0
- package/src/app/api/auth/forgot_password/route.ts +107 -0
- package/src/app/api/auth/library_photos/route.ts +70 -0
- package/src/app/api/auth/login/route.ts +155 -0
- package/src/app/api/auth/logout/route.ts +62 -0
- package/src/app/api/auth/me/route.ts +47 -0
- package/src/app/api/auth/profile_picture/[filename]/route.ts +67 -0
- package/src/app/api/auth/register/route.ts +106 -0
- package/src/app/api/auth/remove_profile_picture/route.ts +86 -0
- package/src/app/api/auth/resend_verification/route.ts +107 -0
- package/src/app/api/auth/reset_password/route.ts +107 -0
- package/src/app/api/auth/update_user/route.ts +126 -0
- package/src/app/api/auth/upload_profile_picture/route.ts +268 -0
- package/src/app/api/auth/validate_reset_token/route.ts +80 -0
- package/src/app/api/auth/verify_email/route.ts +85 -0
- package/src/app/api/migrations/apply/route.ts +91 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/fonts/GeistMonoVF.woff +0 -0
- package/src/app/fonts/GeistVF.woff +0 -0
- package/src/app/forgot_password/forgot_password_page_client.tsx +60 -0
- package/src/app/forgot_password/page.tsx +24 -0
- package/src/app/globals.css +89 -0
- package/src/app/hazo_connect/api/sqlite/data/route.ts +197 -0
- package/src/app/hazo_connect/api/sqlite/schema/route.ts +35 -0
- package/src/app/hazo_connect/api/sqlite/tables/route.ts +26 -0
- package/src/app/hazo_connect/sqlite_admin/page.tsx +51 -0
- package/src/app/hazo_connect/sqlite_admin/sqlite-admin-client.tsx +947 -0
- package/src/app/layout.tsx +43 -0
- package/src/app/login/login_page_client.tsx +71 -0
- package/src/app/login/page.tsx +26 -0
- package/src/app/my_settings/my_settings_page_client.tsx +120 -0
- package/src/app/my_settings/page.tsx +40 -0
- package/src/app/page.tsx +170 -0
- package/src/app/register/page.tsx +26 -0
- package/src/app/register/register_page_client.tsx +72 -0
- package/src/app/reset_password/page.tsx +29 -0
- package/src/app/reset_password/reset_password_page_client.tsx +81 -0
- package/src/app/verify_email/page.tsx +24 -0
- package/src/app/verify_email/verify_email_page_client.tsx +60 -0
- package/src/components/layouts/email_verification/config/email_verification_field_config.ts +86 -0
- package/src/components/layouts/email_verification/hooks/use_email_verification.ts +291 -0
- package/src/components/layouts/email_verification/index.tsx +297 -0
- package/src/components/layouts/forgot_password/config/forgot_password_field_config.ts +58 -0
- package/src/components/layouts/forgot_password/hooks/use_forgot_password_form.ts +179 -0
- package/src/components/layouts/forgot_password/index.tsx +168 -0
- package/src/components/layouts/login/config/login_field_config.ts +67 -0
- package/src/components/layouts/login/hooks/use_login_form.ts +281 -0
- package/src/components/layouts/login/index.tsx +224 -0
- package/src/components/layouts/my_settings/components/editable_field.tsx +177 -0
- package/src/components/layouts/my_settings/components/password_change_dialog.tsx +301 -0
- package/src/components/layouts/my_settings/components/profile_picture_dialog.tsx +385 -0
- package/src/components/layouts/my_settings/components/profile_picture_display.tsx +66 -0
- package/src/components/layouts/my_settings/components/profile_picture_gravatar_tab.tsx +143 -0
- package/src/components/layouts/my_settings/components/profile_picture_library_tab.tsx +282 -0
- package/src/components/layouts/my_settings/components/profile_picture_upload_tab.tsx +341 -0
- package/src/components/layouts/my_settings/config/my_settings_field_config.ts +61 -0
- package/src/components/layouts/my_settings/hooks/use_my_settings.ts +458 -0
- package/src/components/layouts/my_settings/index.tsx +351 -0
- package/src/components/layouts/register/config/register_field_config.ts +101 -0
- package/src/components/layouts/register/hooks/use_register_form.ts +272 -0
- package/src/components/layouts/register/index.tsx +208 -0
- package/src/components/layouts/reset_password/config/reset_password_field_config.ts +86 -0
- package/src/components/layouts/reset_password/hooks/use_reset_password_form.ts +276 -0
- package/src/components/layouts/reset_password/index.tsx +294 -0
- package/src/components/layouts/shared/components/already_logged_in_guard.tsx +95 -0
- package/src/components/layouts/shared/components/field_error_message.tsx +29 -0
- package/src/components/layouts/shared/components/form_action_buttons.tsx +64 -0
- package/src/components/layouts/shared/components/form_field_wrapper.tsx +44 -0
- package/src/components/layouts/shared/components/form_header.tsx +36 -0
- package/src/components/layouts/shared/components/logout_button.tsx +76 -0
- package/src/components/layouts/shared/components/password_field.tsx +72 -0
- package/src/components/layouts/shared/components/sidebar_layout_wrapper.tsx +264 -0
- package/src/components/layouts/shared/components/two_column_auth_layout.tsx +44 -0
- package/src/components/layouts/shared/components/unauthorized_guard.tsx +78 -0
- package/src/components/layouts/shared/components/visual_panel.tsx +41 -0
- package/src/components/layouts/shared/config/layout_customization.ts +95 -0
- package/src/components/layouts/shared/data/layout_data_client.ts +19 -0
- package/src/components/layouts/shared/hooks/use_auth_status.ts +103 -0
- package/src/components/layouts/shared/utils/ip_address.ts +37 -0
- package/src/components/layouts/shared/utils/validation.ts +66 -0
- package/src/components/ui/avatar.tsx +50 -0
- package/src/components/ui/button.tsx +57 -0
- package/src/components/ui/dialog.tsx +122 -0
- package/src/components/ui/hazo_ui_tooltip.tsx +67 -0
- package/src/components/ui/input.tsx +22 -0
- package/src/components/ui/label.tsx +26 -0
- package/src/components/ui/separator.tsx +31 -0
- package/src/components/ui/sheet.tsx +139 -0
- package/src/components/ui/sidebar.tsx +773 -0
- package/src/components/ui/skeleton.tsx +15 -0
- package/src/components/ui/sonner.tsx +31 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/tabs.tsx +55 -0
- package/src/components/ui/tooltip.tsx +32 -0
- package/src/components/ui/vertical-tabs.tsx +59 -0
- package/src/hooks/use-mobile.tsx +19 -0
- package/src/lib/already_logged_in_config.server.ts +46 -0
- package/src/lib/app_logger.ts +24 -0
- package/src/lib/auth/auth_utils.server.ts +196 -0
- package/src/lib/auth/server_auth.ts +88 -0
- package/src/lib/config/config_loader.server.ts +149 -0
- package/src/lib/email_verification_config.server.ts +32 -0
- package/src/lib/file_types_config.server.ts +25 -0
- package/src/lib/forgot_password_config.server.ts +32 -0
- package/src/lib/hazo_connect_instance.server.ts +77 -0
- package/src/lib/hazo_connect_setup.server.ts +181 -0
- package/src/lib/hazo_connect_setup.ts +54 -0
- package/src/lib/login_config.server.ts +46 -0
- package/src/lib/messages_config.server.ts +45 -0
- package/src/lib/migrations/apply_migration.ts +105 -0
- package/src/lib/my_settings_config.server.ts +135 -0
- package/src/lib/password_requirements_config.server.ts +39 -0
- package/src/lib/profile_picture_config.server.ts +56 -0
- package/src/lib/register_config.server.ts +57 -0
- package/src/lib/reset_password_config.server.ts +75 -0
- package/src/lib/services/email_service.ts +581 -0
- package/src/lib/services/email_verification_service.ts +264 -0
- package/src/lib/services/login_service.ts +118 -0
- package/src/lib/services/password_change_service.ts +154 -0
- package/src/lib/services/password_reset_service.ts +405 -0
- package/src/lib/services/profile_picture_remove_service.ts +120 -0
- package/src/lib/services/profile_picture_service.ts +215 -0
- package/src/lib/services/profile_picture_source_mapper.ts +62 -0
- package/src/lib/services/registration_service.ts +163 -0
- package/src/lib/services/token_service.ts +240 -0
- package/src/lib/services/user_update_service.ts +128 -0
- package/src/lib/ui_sizes_config.server.ts +37 -0
- package/src/lib/user_fields_config.server.ts +31 -0
- package/src/lib/utils/api_route_helpers.ts +60 -0
- package/src/lib/utils.ts +11 -0
- package/src/middleware.ts +91 -0
- package/src/server/config/config_loader.ts +496 -0
- package/src/server/index.ts +38 -0
- package/src/server/logging/logger_service.ts +56 -0
- package/src/server/routes/root_router.ts +16 -0
- package/src/server/server.ts +28 -0
- package/src/server/types/app_types.ts +74 -0
- package/src/server/types/express.d.ts +15 -0
- package/src/stories/email_verification_layout.stories.tsx +137 -0
- package/src/stories/forgot_password_layout.stories.tsx +85 -0
- package/src/stories/login_layout.stories.tsx +85 -0
- package/src/stories/project_overview.stories.tsx +33 -0
- package/src/stories/register_layout.stories.tsx +107 -0
- package/tailwind.config.ts +77 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// file_description: reusable visual panel component for displaying images in authentication layouts
|
|
2
|
+
// section: client_directive
|
|
3
|
+
"use client";
|
|
4
|
+
|
|
5
|
+
// section: imports
|
|
6
|
+
import Image from "next/image";
|
|
7
|
+
|
|
8
|
+
// section: types
|
|
9
|
+
type VisualPanelProps = {
|
|
10
|
+
imageSrc: string;
|
|
11
|
+
imageAlt: string;
|
|
12
|
+
backgroundColor?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// section: component
|
|
17
|
+
export function VisualPanel({
|
|
18
|
+
imageSrc,
|
|
19
|
+
imageAlt,
|
|
20
|
+
backgroundColor = "#f1f5f9",
|
|
21
|
+
className,
|
|
22
|
+
}: VisualPanelProps) {
|
|
23
|
+
return (
|
|
24
|
+
<div
|
|
25
|
+
className={`cls_visual_panel relative hidden h-full w-full items-center justify-center md:flex ${className ?? ""}`}
|
|
26
|
+
style={{ backgroundColor }}
|
|
27
|
+
>
|
|
28
|
+
<div className="cls_visual_panel_image_wrapper relative h-full w-full">
|
|
29
|
+
<Image
|
|
30
|
+
src={imageSrc}
|
|
31
|
+
alt={imageAlt}
|
|
32
|
+
fill
|
|
33
|
+
sizes="(min-width: 768px) 50vw, 100vw"
|
|
34
|
+
className="cls_visual_panel_image object-cover"
|
|
35
|
+
priority
|
|
36
|
+
/>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// file_description: provide reusable configuration helpers for layout components
|
|
2
|
+
// section: types
|
|
3
|
+
export type LayoutFieldId = string;
|
|
4
|
+
|
|
5
|
+
export type LayoutFieldDefinition = {
|
|
6
|
+
id: LayoutFieldId;
|
|
7
|
+
label: string;
|
|
8
|
+
type: "text" | "email" | "password";
|
|
9
|
+
autoComplete?: string;
|
|
10
|
+
placeholder: string;
|
|
11
|
+
ariaLabel: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type LayoutFieldMap = Record<LayoutFieldId, LayoutFieldDefinition>;
|
|
15
|
+
export type LayoutFieldMapOverrides = Partial<Record<LayoutFieldId, Partial<LayoutFieldDefinition>>>;
|
|
16
|
+
|
|
17
|
+
export type LayoutLabelDefaults = {
|
|
18
|
+
heading: string;
|
|
19
|
+
subHeading: string;
|
|
20
|
+
submitButton: string;
|
|
21
|
+
cancelButton: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type LayoutLabelOverrides = Partial<LayoutLabelDefaults>;
|
|
25
|
+
|
|
26
|
+
export type ButtonPaletteDefaults = {
|
|
27
|
+
submitBackground: string;
|
|
28
|
+
submitText: string;
|
|
29
|
+
cancelBorder: string;
|
|
30
|
+
cancelText: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type ButtonPaletteOverrides = Partial<ButtonPaletteDefaults>;
|
|
34
|
+
|
|
35
|
+
export type PasswordRequirementOptions = {
|
|
36
|
+
minimum_length: number;
|
|
37
|
+
require_uppercase: boolean;
|
|
38
|
+
require_lowercase: boolean;
|
|
39
|
+
require_number: boolean;
|
|
40
|
+
require_special: boolean;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type PasswordRequirementOverrides = Partial<PasswordRequirementOptions>;
|
|
44
|
+
|
|
45
|
+
// section: helpers
|
|
46
|
+
export const resolveFieldDefinitions = (
|
|
47
|
+
baseDefinitions: LayoutFieldMap,
|
|
48
|
+
overrides?: LayoutFieldMapOverrides,
|
|
49
|
+
): LayoutFieldMap => {
|
|
50
|
+
if (!overrides) {
|
|
51
|
+
return baseDefinitions;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const merged: LayoutFieldMap = { ...baseDefinitions };
|
|
55
|
+
|
|
56
|
+
Object.entries(overrides).forEach(([fieldId, definitionOverride]) => {
|
|
57
|
+
if (!definitionOverride) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const existing = merged[fieldId] ?? (definitionOverride as LayoutFieldDefinition);
|
|
62
|
+
merged[fieldId] = {
|
|
63
|
+
...existing,
|
|
64
|
+
...definitionOverride,
|
|
65
|
+
id: existing.id ?? (fieldId as LayoutFieldId),
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return merged;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const resolveLabels = (
|
|
73
|
+
defaults: LayoutLabelDefaults,
|
|
74
|
+
overrides?: LayoutLabelOverrides,
|
|
75
|
+
): LayoutLabelDefaults => ({
|
|
76
|
+
...defaults,
|
|
77
|
+
...(overrides ?? {}),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export const resolveButtonPalette = (
|
|
81
|
+
defaults: ButtonPaletteDefaults,
|
|
82
|
+
overrides?: ButtonPaletteOverrides,
|
|
83
|
+
): ButtonPaletteDefaults => ({
|
|
84
|
+
...defaults,
|
|
85
|
+
...(overrides ?? {}),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export const resolvePasswordRequirements = (
|
|
89
|
+
defaults: PasswordRequirementOptions,
|
|
90
|
+
overrides?: PasswordRequirementOverrides,
|
|
91
|
+
): PasswordRequirementOptions => ({
|
|
92
|
+
...defaults,
|
|
93
|
+
...(overrides ?? {}),
|
|
94
|
+
});
|
|
95
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// file_description: expose a common data client wrapper for layout components
|
|
2
|
+
// section: types
|
|
3
|
+
export type LayoutDataClient<TClient = unknown> = {
|
|
4
|
+
client: TClient;
|
|
5
|
+
healthCheck: () => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// section: factory
|
|
9
|
+
export const createLayoutDataClient = <TClient,>(
|
|
10
|
+
hazoClient: TClient,
|
|
11
|
+
): LayoutDataClient<TClient> => ({
|
|
12
|
+
client: hazoClient,
|
|
13
|
+
healthCheck: async () => {
|
|
14
|
+
if (hazoClient && typeof (hazoClient as Record<string, unknown>).healthCheck === "function") {
|
|
15
|
+
await ((hazoClient as unknown) as { healthCheck: () => Promise<void> }).healthCheck();
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// file_description: hook to check authentication status and get current user info
|
|
2
|
+
// section: client_directive
|
|
3
|
+
"use client";
|
|
4
|
+
|
|
5
|
+
// section: imports
|
|
6
|
+
import { useState, useEffect, useCallback } from "react";
|
|
7
|
+
|
|
8
|
+
// section: types
|
|
9
|
+
export type AuthStatusData = {
|
|
10
|
+
authenticated: boolean;
|
|
11
|
+
user_id?: string;
|
|
12
|
+
email?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
email_verified?: boolean;
|
|
15
|
+
last_logon?: string;
|
|
16
|
+
profile_picture_url?: string;
|
|
17
|
+
profile_source?: "upload" | "library" | "gravatar" | "custom";
|
|
18
|
+
loading: boolean;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type AuthStatus = AuthStatusData & {
|
|
22
|
+
refresh: () => Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// section: constants
|
|
26
|
+
const AUTH_STATUS_CHANGE_EVENT = "hazo_auth_status_change";
|
|
27
|
+
|
|
28
|
+
// section: helpers
|
|
29
|
+
/**
|
|
30
|
+
* Dispatches a custom event to notify all auth status hooks to refresh
|
|
31
|
+
*/
|
|
32
|
+
export function trigger_auth_status_refresh(): void {
|
|
33
|
+
if (typeof window !== "undefined") {
|
|
34
|
+
window.dispatchEvent(new CustomEvent(AUTH_STATUS_CHANGE_EVENT));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// section: hook
|
|
39
|
+
export function use_auth_status(): AuthStatus {
|
|
40
|
+
const [authStatus, setAuthStatus] = useState<AuthStatusData>({
|
|
41
|
+
authenticated: false,
|
|
42
|
+
loading: true,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const checkAuth = useCallback(async () => {
|
|
46
|
+
setAuthStatus((prev) => ({ ...prev, loading: true }));
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const response = await fetch("/api/auth/me", {
|
|
50
|
+
method: "GET",
|
|
51
|
+
credentials: "include",
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const data = await response.json();
|
|
55
|
+
|
|
56
|
+
if (data.authenticated) {
|
|
57
|
+
setAuthStatus({
|
|
58
|
+
authenticated: true,
|
|
59
|
+
user_id: data.user_id,
|
|
60
|
+
email: data.email,
|
|
61
|
+
name: data.name,
|
|
62
|
+
email_verified: data.email_verified,
|
|
63
|
+
last_logon: data.last_logon,
|
|
64
|
+
profile_picture_url: data.profile_picture_url,
|
|
65
|
+
profile_source: data.profile_source,
|
|
66
|
+
loading: false,
|
|
67
|
+
});
|
|
68
|
+
} else {
|
|
69
|
+
setAuthStatus({
|
|
70
|
+
authenticated: false,
|
|
71
|
+
loading: false,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
setAuthStatus({
|
|
76
|
+
authenticated: false,
|
|
77
|
+
loading: false,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}, []);
|
|
81
|
+
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
// Check auth status on mount
|
|
84
|
+
void checkAuth();
|
|
85
|
+
|
|
86
|
+
// Listen for auth status change events
|
|
87
|
+
const handleAuthChange = () => {
|
|
88
|
+
void checkAuth();
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
window.addEventListener(AUTH_STATUS_CHANGE_EVENT, handleAuthChange);
|
|
92
|
+
|
|
93
|
+
return () => {
|
|
94
|
+
window.removeEventListener(AUTH_STATUS_CHANGE_EVENT, handleAuthChange);
|
|
95
|
+
};
|
|
96
|
+
}, [checkAuth]);
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
...authStatus,
|
|
100
|
+
refresh: checkAuth,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// file_description: utility functions for collecting client IP address
|
|
2
|
+
// section: client_ip_collection
|
|
3
|
+
/**
|
|
4
|
+
* Attempts to get the client IP address
|
|
5
|
+
* In browser context, this will try to fetch from an API endpoint
|
|
6
|
+
* Falls back to "unknown" if unable to determine
|
|
7
|
+
*/
|
|
8
|
+
export async function get_client_ip(): Promise<string> {
|
|
9
|
+
// Check if fetch is available (not available in test environment)
|
|
10
|
+
if (typeof fetch === "undefined") {
|
|
11
|
+
return "unknown";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
// Try to get IP from a public IP detection service
|
|
16
|
+
const response = await fetch("https://api.ipify.org?format=json", {
|
|
17
|
+
method: "GET",
|
|
18
|
+
headers: {
|
|
19
|
+
"Accept": "application/json",
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (response.ok) {
|
|
24
|
+
const data = await response.json();
|
|
25
|
+
return data.ip || "unknown";
|
|
26
|
+
}
|
|
27
|
+
} catch (error) {
|
|
28
|
+
// Silently fail and return unknown
|
|
29
|
+
// Only log in non-test environments
|
|
30
|
+
if (process.env.NODE_ENV !== "test") {
|
|
31
|
+
console.debug("Failed to fetch IP address:", error);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return "unknown";
|
|
36
|
+
}
|
|
37
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// file_description: provide shared validation utilities for email and password fields across layout components
|
|
2
|
+
// section: imports
|
|
3
|
+
import type { PasswordRequirementOptions } from "@/components/layouts/shared/config/layout_customization";
|
|
4
|
+
|
|
5
|
+
// section: constants
|
|
6
|
+
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
7
|
+
|
|
8
|
+
// section: email_validation
|
|
9
|
+
/**
|
|
10
|
+
* Validates an email address format
|
|
11
|
+
* @param email - The email address to validate
|
|
12
|
+
* @returns Error message string if invalid, undefined if valid
|
|
13
|
+
*/
|
|
14
|
+
export function validateEmail(email: string): string | undefined {
|
|
15
|
+
const trimmedEmail = email.trim();
|
|
16
|
+
if (trimmedEmail.length > 0 && !EMAIL_PATTERN.test(trimmedEmail)) {
|
|
17
|
+
return "enter a valid email address";
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// section: password_validation
|
|
23
|
+
/**
|
|
24
|
+
* Validates a password against specified requirements
|
|
25
|
+
* @param password - The password to validate
|
|
26
|
+
* @param requirements - Password requirement options
|
|
27
|
+
* @returns Array of error message strings if invalid, undefined if valid
|
|
28
|
+
*/
|
|
29
|
+
export function validatePassword(
|
|
30
|
+
password: string,
|
|
31
|
+
requirements: PasswordRequirementOptions,
|
|
32
|
+
): string[] | undefined {
|
|
33
|
+
if (password.trim().length === 0) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const messages: string[] = [];
|
|
38
|
+
|
|
39
|
+
if (password.length < requirements.minimum_length) {
|
|
40
|
+
messages.push(
|
|
41
|
+
`Password must be at least ${requirements.minimum_length} characters.`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (requirements.require_uppercase && !/[A-Z]/.test(password)) {
|
|
46
|
+
messages.push("Password must include at least one uppercase letter.");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (requirements.require_lowercase && !/[a-z]/.test(password)) {
|
|
50
|
+
messages.push("Password must include at least one lowercase letter.");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (requirements.require_number && !/\d/.test(password)) {
|
|
54
|
+
messages.push("Password must include at least one number.");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (
|
|
58
|
+
requirements.require_special &&
|
|
59
|
+
!/[!@#$%^&*(),.?":{}|<>\-_+=\[\];'/\\]/.test(password)
|
|
60
|
+
) {
|
|
61
|
+
messages.push("Password must include at least one special character.");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return messages.length > 0 ? messages : undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as AvatarPrimitive from "@radix-ui/react-avatar"
|
|
5
|
+
|
|
6
|
+
import { cn } from "@/lib/utils"
|
|
7
|
+
|
|
8
|
+
const Avatar = React.forwardRef<
|
|
9
|
+
React.ElementRef<typeof AvatarPrimitive.Root>,
|
|
10
|
+
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
|
|
11
|
+
>(({ className, ...props }, ref) => (
|
|
12
|
+
<AvatarPrimitive.Root
|
|
13
|
+
ref={ref}
|
|
14
|
+
className={cn(
|
|
15
|
+
"relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
|
|
16
|
+
className
|
|
17
|
+
)}
|
|
18
|
+
{...props}
|
|
19
|
+
/>
|
|
20
|
+
))
|
|
21
|
+
Avatar.displayName = AvatarPrimitive.Root.displayName
|
|
22
|
+
|
|
23
|
+
const AvatarImage = React.forwardRef<
|
|
24
|
+
React.ElementRef<typeof AvatarPrimitive.Image>,
|
|
25
|
+
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
|
|
26
|
+
>(({ className, ...props }, ref) => (
|
|
27
|
+
<AvatarPrimitive.Image
|
|
28
|
+
ref={ref}
|
|
29
|
+
className={cn("aspect-square h-full w-full", className)}
|
|
30
|
+
{...props}
|
|
31
|
+
/>
|
|
32
|
+
))
|
|
33
|
+
AvatarImage.displayName = AvatarPrimitive.Image.displayName
|
|
34
|
+
|
|
35
|
+
const AvatarFallback = React.forwardRef<
|
|
36
|
+
React.ElementRef<typeof AvatarPrimitive.Fallback>,
|
|
37
|
+
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
|
|
38
|
+
>(({ className, ...props }, ref) => (
|
|
39
|
+
<AvatarPrimitive.Fallback
|
|
40
|
+
ref={ref}
|
|
41
|
+
className={cn(
|
|
42
|
+
"flex h-full w-full items-center justify-center rounded-full bg-muted",
|
|
43
|
+
className
|
|
44
|
+
)}
|
|
45
|
+
{...props}
|
|
46
|
+
/>
|
|
47
|
+
))
|
|
48
|
+
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName
|
|
49
|
+
|
|
50
|
+
export { Avatar, AvatarImage, AvatarFallback }
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { Slot } from "@radix-ui/react-slot"
|
|
3
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
|
|
7
|
+
const buttonVariants = cva(
|
|
8
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default:
|
|
13
|
+
"bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
|
14
|
+
destructive:
|
|
15
|
+
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
|
16
|
+
outline:
|
|
17
|
+
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
|
18
|
+
secondary:
|
|
19
|
+
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
|
20
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
21
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
22
|
+
},
|
|
23
|
+
size: {
|
|
24
|
+
default: "h-9 px-4 py-2",
|
|
25
|
+
sm: "h-8 rounded-md px-3 text-xs",
|
|
26
|
+
lg: "h-10 rounded-md px-8",
|
|
27
|
+
icon: "h-9 w-9",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
defaultVariants: {
|
|
31
|
+
variant: "default",
|
|
32
|
+
size: "default",
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
export interface ButtonProps
|
|
38
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
39
|
+
VariantProps<typeof buttonVariants> {
|
|
40
|
+
asChild?: boolean
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
44
|
+
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
45
|
+
const Comp = asChild ? Slot : "button"
|
|
46
|
+
return (
|
|
47
|
+
<Comp
|
|
48
|
+
className={cn(buttonVariants({ variant, size, className }))}
|
|
49
|
+
ref={ref}
|
|
50
|
+
{...props}
|
|
51
|
+
/>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
Button.displayName = "Button"
|
|
56
|
+
|
|
57
|
+
export { Button, buttonVariants }
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as DialogPrimitive from "@radix-ui/react-dialog"
|
|
5
|
+
import { X } from "lucide-react"
|
|
6
|
+
|
|
7
|
+
import { cn } from "@/lib/utils"
|
|
8
|
+
|
|
9
|
+
const Dialog = DialogPrimitive.Root
|
|
10
|
+
|
|
11
|
+
const DialogTrigger = DialogPrimitive.Trigger
|
|
12
|
+
|
|
13
|
+
const DialogPortal = DialogPrimitive.Portal
|
|
14
|
+
|
|
15
|
+
const DialogClose = DialogPrimitive.Close
|
|
16
|
+
|
|
17
|
+
const DialogOverlay = React.forwardRef<
|
|
18
|
+
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
|
19
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
|
20
|
+
>(({ className, ...props }, ref) => (
|
|
21
|
+
<DialogPrimitive.Overlay
|
|
22
|
+
ref={ref}
|
|
23
|
+
className={cn(
|
|
24
|
+
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
|
25
|
+
className
|
|
26
|
+
)}
|
|
27
|
+
{...props}
|
|
28
|
+
/>
|
|
29
|
+
))
|
|
30
|
+
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
|
|
31
|
+
|
|
32
|
+
const DialogContent = React.forwardRef<
|
|
33
|
+
React.ElementRef<typeof DialogPrimitive.Content>,
|
|
34
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
|
35
|
+
>(({ className, children, ...props }, ref) => (
|
|
36
|
+
<DialogPortal>
|
|
37
|
+
<DialogOverlay />
|
|
38
|
+
<DialogPrimitive.Content
|
|
39
|
+
ref={ref}
|
|
40
|
+
className={cn(
|
|
41
|
+
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
|
|
42
|
+
className
|
|
43
|
+
)}
|
|
44
|
+
{...props}
|
|
45
|
+
>
|
|
46
|
+
{children}
|
|
47
|
+
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
|
|
48
|
+
<X className="h-4 w-4" />
|
|
49
|
+
<span className="sr-only">Close</span>
|
|
50
|
+
</DialogPrimitive.Close>
|
|
51
|
+
</DialogPrimitive.Content>
|
|
52
|
+
</DialogPortal>
|
|
53
|
+
))
|
|
54
|
+
DialogContent.displayName = DialogPrimitive.Content.displayName
|
|
55
|
+
|
|
56
|
+
const DialogHeader = ({
|
|
57
|
+
className,
|
|
58
|
+
...props
|
|
59
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
60
|
+
<div
|
|
61
|
+
className={cn(
|
|
62
|
+
"flex flex-col space-y-1.5 text-center sm:text-left",
|
|
63
|
+
className
|
|
64
|
+
)}
|
|
65
|
+
{...props}
|
|
66
|
+
/>
|
|
67
|
+
)
|
|
68
|
+
DialogHeader.displayName = "DialogHeader"
|
|
69
|
+
|
|
70
|
+
const DialogFooter = ({
|
|
71
|
+
className,
|
|
72
|
+
...props
|
|
73
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
74
|
+
<div
|
|
75
|
+
className={cn(
|
|
76
|
+
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
|
77
|
+
className
|
|
78
|
+
)}
|
|
79
|
+
{...props}
|
|
80
|
+
/>
|
|
81
|
+
)
|
|
82
|
+
DialogFooter.displayName = "DialogFooter"
|
|
83
|
+
|
|
84
|
+
const DialogTitle = React.forwardRef<
|
|
85
|
+
React.ElementRef<typeof DialogPrimitive.Title>,
|
|
86
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
|
87
|
+
>(({ className, ...props }, ref) => (
|
|
88
|
+
<DialogPrimitive.Title
|
|
89
|
+
ref={ref}
|
|
90
|
+
className={cn(
|
|
91
|
+
"text-lg font-semibold leading-none tracking-tight",
|
|
92
|
+
className
|
|
93
|
+
)}
|
|
94
|
+
{...props}
|
|
95
|
+
/>
|
|
96
|
+
))
|
|
97
|
+
DialogTitle.displayName = DialogPrimitive.Title.displayName
|
|
98
|
+
|
|
99
|
+
const DialogDescription = React.forwardRef<
|
|
100
|
+
React.ElementRef<typeof DialogPrimitive.Description>,
|
|
101
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
|
102
|
+
>(({ className, ...props }, ref) => (
|
|
103
|
+
<DialogPrimitive.Description
|
|
104
|
+
ref={ref}
|
|
105
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
106
|
+
{...props}
|
|
107
|
+
/>
|
|
108
|
+
))
|
|
109
|
+
DialogDescription.displayName = DialogPrimitive.Description.displayName
|
|
110
|
+
|
|
111
|
+
export {
|
|
112
|
+
Dialog,
|
|
113
|
+
DialogPortal,
|
|
114
|
+
DialogOverlay,
|
|
115
|
+
DialogTrigger,
|
|
116
|
+
DialogClose,
|
|
117
|
+
DialogContent,
|
|
118
|
+
DialogHeader,
|
|
119
|
+
DialogFooter,
|
|
120
|
+
DialogTitle,
|
|
121
|
+
DialogDescription,
|
|
122
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// file_description: reusable tooltip component for hazo_auth with question mark icon
|
|
2
|
+
// section: client_directive
|
|
3
|
+
"use client";
|
|
4
|
+
|
|
5
|
+
// section: imports
|
|
6
|
+
import { HelpCircle } from "lucide-react";
|
|
7
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
|
8
|
+
|
|
9
|
+
// section: types
|
|
10
|
+
export type HazoUITooltipProps = {
|
|
11
|
+
/**
|
|
12
|
+
* The tooltip message to display
|
|
13
|
+
*/
|
|
14
|
+
message: string;
|
|
15
|
+
/**
|
|
16
|
+
* Optional custom icon size (default: 16)
|
|
17
|
+
*/
|
|
18
|
+
iconSize?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Optional custom icon className
|
|
21
|
+
*/
|
|
22
|
+
iconClassName?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Optional side for tooltip placement (default: "top")
|
|
25
|
+
*/
|
|
26
|
+
side?: "top" | "right" | "bottom" | "left";
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// section: component
|
|
30
|
+
/**
|
|
31
|
+
* Reusable tooltip component with question mark icon
|
|
32
|
+
* Displays a help icon that shows a tooltip message on hover
|
|
33
|
+
* @param props - Component props including message, icon size, and placement
|
|
34
|
+
* @returns Tooltip component with question mark icon
|
|
35
|
+
*/
|
|
36
|
+
export function HazoUITooltip({
|
|
37
|
+
message,
|
|
38
|
+
iconSize = 16,
|
|
39
|
+
iconClassName = "text-slate-400 hover:text-slate-600",
|
|
40
|
+
side = "top",
|
|
41
|
+
}: HazoUITooltipProps) {
|
|
42
|
+
return (
|
|
43
|
+
<TooltipProvider>
|
|
44
|
+
<Tooltip>
|
|
45
|
+
<TooltipTrigger asChild>
|
|
46
|
+
<button
|
|
47
|
+
type="button"
|
|
48
|
+
className="cls_hazo_ui_tooltip_trigger inline-flex items-start focus:outline-none align-super"
|
|
49
|
+
aria-label="Help"
|
|
50
|
+
style={{ verticalAlign: "super" }}
|
|
51
|
+
>
|
|
52
|
+
<HelpCircle
|
|
53
|
+
size={iconSize}
|
|
54
|
+
className={`cls_hazo_ui_tooltip_icon ${iconClassName}`}
|
|
55
|
+
aria-hidden="true"
|
|
56
|
+
style={{ transform: "translateY(-0.2em)" }}
|
|
57
|
+
/>
|
|
58
|
+
</button>
|
|
59
|
+
</TooltipTrigger>
|
|
60
|
+
<TooltipContent side={side} className="cls_hazo_ui_tooltip_content">
|
|
61
|
+
<p className="cls_hazo_ui_tooltip_message">{message}</p>
|
|
62
|
+
</TooltipContent>
|
|
63
|
+
</Tooltip>
|
|
64
|
+
</TooltipProvider>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { cn } from "@/lib/utils"
|
|
4
|
+
|
|
5
|
+
const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>(
|
|
6
|
+
({ className, type, ...props }, ref) => {
|
|
7
|
+
return (
|
|
8
|
+
<input
|
|
9
|
+
type={type}
|
|
10
|
+
className={cn(
|
|
11
|
+
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
|
12
|
+
className
|
|
13
|
+
)}
|
|
14
|
+
ref={ref}
|
|
15
|
+
{...props}
|
|
16
|
+
/>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
Input.displayName = "Input"
|
|
21
|
+
|
|
22
|
+
export { Input }
|