hazo_auth 1.0.1 → 1.0.3
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 +283 -0
- package/hazo_auth_config.example.ini +5 -0
- package/package.json +3 -3
- package/src/app/api/hazo_auth/resend_verification/route.ts +6 -5
- package/src/components/layouts/email_verification/hooks/use_email_verification.ts +11 -5
- package/src/lib/hazo_connect_instance.server.ts +38 -14
- package/src/lib/hazo_connect_setup.server.ts +18 -4
- package/src/lib/services/email_verification_service.ts +6 -0
- package/src/middleware.ts +1 -0
package/README.md
CHANGED
|
@@ -655,6 +655,289 @@ You can also manually invalidate the cache using the API endpoint:
|
|
|
655
655
|
// Body: { user_id?: string, role_ids?: number[], invalidate_all?: boolean }
|
|
656
656
|
```
|
|
657
657
|
|
|
658
|
+
## Profile Picture Menu Widget
|
|
659
|
+
|
|
660
|
+
The Profile Picture Menu is a versatile component for navbar or sidebar that automatically displays:
|
|
661
|
+
- **When authenticated**: User's profile picture with a dropdown menu containing user info, settings link, logout, and custom menu items
|
|
662
|
+
- **When not authenticated**: Sign Up and Sign In buttons (or a single button, configurable)
|
|
663
|
+
|
|
664
|
+
### Basic Usage (Recommended)
|
|
665
|
+
|
|
666
|
+
Use the `ProfilePicMenuWrapper` component which automatically loads configuration from `hazo_auth_config.ini`:
|
|
667
|
+
|
|
668
|
+
```typescript
|
|
669
|
+
// In your navbar or layout component
|
|
670
|
+
import { ProfilePicMenuWrapper } from "hazo_auth/components/layouts/shared/components/profile_pic_menu_wrapper";
|
|
671
|
+
|
|
672
|
+
export function Navbar() {
|
|
673
|
+
return (
|
|
674
|
+
<nav className="flex items-center justify-between p-4">
|
|
675
|
+
<div>Logo</div>
|
|
676
|
+
<ProfilePicMenuWrapper
|
|
677
|
+
avatar_size="default" // "sm" | "default" | "lg"
|
|
678
|
+
className="ml-auto"
|
|
679
|
+
/>
|
|
680
|
+
</nav>
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
### Direct Usage (Manual Configuration)
|
|
686
|
+
|
|
687
|
+
If you prefer to configure the component directly without using the config file:
|
|
688
|
+
|
|
689
|
+
```typescript
|
|
690
|
+
"use client";
|
|
691
|
+
|
|
692
|
+
import { ProfilePicMenu } from "hazo_auth/components/layouts/shared/components/profile_pic_menu";
|
|
693
|
+
|
|
694
|
+
export function Navbar() {
|
|
695
|
+
return (
|
|
696
|
+
<nav className="flex items-center justify-between p-4">
|
|
697
|
+
<div>Logo</div>
|
|
698
|
+
<ProfilePicMenu
|
|
699
|
+
show_single_button={false}
|
|
700
|
+
sign_up_label="Sign Up"
|
|
701
|
+
sign_in_label="Sign In"
|
|
702
|
+
register_path="/hazo_auth/register"
|
|
703
|
+
login_path="/hazo_auth/login"
|
|
704
|
+
settings_path="/hazo_auth/my_settings"
|
|
705
|
+
logout_path="/api/hazo_auth/logout"
|
|
706
|
+
avatar_size="default"
|
|
707
|
+
className="ml-auto"
|
|
708
|
+
/>
|
|
709
|
+
</nav>
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
### Configuration
|
|
715
|
+
|
|
716
|
+
Configure the Profile Picture Menu in `hazo_auth_config.ini` under the `[hazo_auth__profile_pic_menu]` section:
|
|
717
|
+
|
|
718
|
+
```ini
|
|
719
|
+
[hazo_auth__profile_pic_menu]
|
|
720
|
+
# Button configuration for unauthenticated users
|
|
721
|
+
# Show only "Sign Up" button when true, show both "Sign Up" and "Sign In" buttons when false (default)
|
|
722
|
+
show_single_button = false
|
|
723
|
+
|
|
724
|
+
# Sign up button label
|
|
725
|
+
sign_up_label = Sign Up
|
|
726
|
+
|
|
727
|
+
# Sign in button label
|
|
728
|
+
sign_in_label = Sign In
|
|
729
|
+
|
|
730
|
+
# Register page path
|
|
731
|
+
register_path = /hazo_auth/register
|
|
732
|
+
|
|
733
|
+
# Login page path
|
|
734
|
+
login_path = /hazo_auth/login
|
|
735
|
+
|
|
736
|
+
# Settings page path (shown in dropdown menu when authenticated)
|
|
737
|
+
settings_path = /hazo_auth/my_settings
|
|
738
|
+
|
|
739
|
+
# Logout API endpoint path
|
|
740
|
+
logout_path = /api/hazo_auth/logout
|
|
741
|
+
|
|
742
|
+
# Custom menu items (optional)
|
|
743
|
+
# Format: "type:label:value_or_href:order" for info/link, or "separator:order" for separator
|
|
744
|
+
# Examples:
|
|
745
|
+
# - Info item: "info:Phone:+1234567890:3"
|
|
746
|
+
# - Link item: "link:My Account:/account:4"
|
|
747
|
+
# - Separator: "separator:2"
|
|
748
|
+
# Custom items are added to the default menu items (name, email, separator, Settings, Logout)
|
|
749
|
+
# Items are sorted by type (info first, then separators, then links) and then by order within each type
|
|
750
|
+
custom_menu_items =
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
### Component Props
|
|
754
|
+
|
|
755
|
+
#### `ProfilePicMenuWrapper` Props
|
|
756
|
+
|
|
757
|
+
- `className?: string` - Additional CSS classes
|
|
758
|
+
- `avatar_size?: "sm" | "default" | "lg"` - Size of the profile picture avatar (default: "default")
|
|
759
|
+
|
|
760
|
+
#### `ProfilePicMenu` Props
|
|
761
|
+
|
|
762
|
+
- `show_single_button?: boolean` - Show only "Sign Up" button when true (default: false)
|
|
763
|
+
- `sign_up_label?: string` - Label for sign up button (default: "Sign Up")
|
|
764
|
+
- `sign_in_label?: string` - Label for sign in button (default: "Sign In")
|
|
765
|
+
- `register_path?: string` - Path to registration page (default: "/hazo_auth/register")
|
|
766
|
+
- `login_path?: string` - Path to login page (default: "/hazo_auth/login")
|
|
767
|
+
- `settings_path?: string` - Path to settings page (default: "/hazo_auth/my_settings")
|
|
768
|
+
- `logout_path?: string` - Path to logout API endpoint (default: "/api/hazo_auth/logout")
|
|
769
|
+
- `custom_menu_items?: ProfilePicMenuMenuItem[]` - Array of custom menu items
|
|
770
|
+
- `className?: string` - Additional CSS classes
|
|
771
|
+
- `avatar_size?: "sm" | "default" | "lg"` - Size of the profile picture avatar (default: "default")
|
|
772
|
+
|
|
773
|
+
### Custom Menu Items
|
|
774
|
+
|
|
775
|
+
You can add custom menu items to the dropdown menu. Items are automatically sorted by type (info → separator → link) and then by order.
|
|
776
|
+
|
|
777
|
+
**Menu Item Types:**
|
|
778
|
+
|
|
779
|
+
1. **Info** - Display-only text (e.g., phone number, department)
|
|
780
|
+
- Format: `"info:label:value:order"`
|
|
781
|
+
- Example: `"info:Phone:+1234567890:3"`
|
|
782
|
+
|
|
783
|
+
2. **Link** - Clickable menu item that navigates to a URL
|
|
784
|
+
- Format: `"link:label:href:order"`
|
|
785
|
+
- Example: `"link:My Account:/account:4"`
|
|
786
|
+
|
|
787
|
+
3. **Separator** - Visual separator line
|
|
788
|
+
- Format: `"separator:order"`
|
|
789
|
+
- Example: `"separator:2"`
|
|
790
|
+
|
|
791
|
+
**Example Configuration:**
|
|
792
|
+
|
|
793
|
+
```ini
|
|
794
|
+
[hazo_auth__profile_pic_menu]
|
|
795
|
+
# Add custom menu items
|
|
796
|
+
custom_menu_items = info:Phone:+1234567890:3,separator:2,link:My Account:/account:4,link:Help:/help:5
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
This will create a menu with:
|
|
800
|
+
1. Default items (name, email, separator, Settings, Logout)
|
|
801
|
+
2. Custom info item: "Phone: +1234567890" (order 3)
|
|
802
|
+
3. Custom separator (order 2)
|
|
803
|
+
4. Custom link: "My Account" → `/account` (order 4)
|
|
804
|
+
5. Custom link: "Help" → `/help` (order 5)
|
|
805
|
+
|
|
806
|
+
Items are sorted by type priority (info < separator < link) and then by order within each type.
|
|
807
|
+
|
|
808
|
+
### Default Menu Items
|
|
809
|
+
|
|
810
|
+
When authenticated, the dropdown menu automatically includes:
|
|
811
|
+
- User's name (if available)
|
|
812
|
+
- User's email address
|
|
813
|
+
- Separator
|
|
814
|
+
- Settings link (with Settings icon)
|
|
815
|
+
- Logout link (with LogOut icon, triggers logout action)
|
|
816
|
+
|
|
817
|
+
### Examples
|
|
818
|
+
|
|
819
|
+
#### Example 1: Simple Navbar Integration
|
|
820
|
+
|
|
821
|
+
```typescript
|
|
822
|
+
// app/components/navbar.tsx
|
|
823
|
+
import { ProfilePicMenuWrapper } from "hazo_auth/components/layouts/shared/components/profile_pic_menu_wrapper";
|
|
824
|
+
|
|
825
|
+
export function Navbar() {
|
|
826
|
+
return (
|
|
827
|
+
<header className="border-b">
|
|
828
|
+
<nav className="container mx-auto flex items-center justify-between p-4">
|
|
829
|
+
<div className="text-xl font-bold">My App</div>
|
|
830
|
+
<ProfilePicMenuWrapper />
|
|
831
|
+
</nav>
|
|
832
|
+
</header>
|
|
833
|
+
);
|
|
834
|
+
}
|
|
835
|
+
```
|
|
836
|
+
|
|
837
|
+
#### Example 2: Custom Styling and Size
|
|
838
|
+
|
|
839
|
+
```typescript
|
|
840
|
+
// app/components/navbar.tsx
|
|
841
|
+
import { ProfilePicMenuWrapper } from "hazo_auth/components/layouts/shared/components/profile_pic_menu_wrapper";
|
|
842
|
+
|
|
843
|
+
export function Navbar() {
|
|
844
|
+
return (
|
|
845
|
+
<header className="bg-slate-900 text-white">
|
|
846
|
+
<nav className="container mx-auto flex items-center justify-between p-4">
|
|
847
|
+
<div className="text-xl font-bold">My App</div>
|
|
848
|
+
<ProfilePicMenuWrapper
|
|
849
|
+
avatar_size="sm"
|
|
850
|
+
className="bg-slate-800 rounded-lg p-2"
|
|
851
|
+
/>
|
|
852
|
+
</nav>
|
|
853
|
+
</header>
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
```
|
|
857
|
+
|
|
858
|
+
#### Example 3: With Custom Menu Items (Programmatic)
|
|
859
|
+
|
|
860
|
+
```typescript
|
|
861
|
+
"use client";
|
|
862
|
+
|
|
863
|
+
import { ProfilePicMenu } from "hazo_auth/components/layouts/shared/components/profile_pic_menu";
|
|
864
|
+
import type { ProfilePicMenuMenuItem } from "hazo_auth/lib/profile_pic_menu_config.server";
|
|
865
|
+
|
|
866
|
+
export function Navbar() {
|
|
867
|
+
const customItems: ProfilePicMenuMenuItem[] = [
|
|
868
|
+
{
|
|
869
|
+
type: "info",
|
|
870
|
+
label: "Department",
|
|
871
|
+
value: "Engineering",
|
|
872
|
+
order: 3,
|
|
873
|
+
id: "dept_info",
|
|
874
|
+
},
|
|
875
|
+
{
|
|
876
|
+
type: "separator",
|
|
877
|
+
order: 2,
|
|
878
|
+
id: "custom_sep",
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
type: "link",
|
|
882
|
+
label: "Documentation",
|
|
883
|
+
href: "/docs",
|
|
884
|
+
order: 4,
|
|
885
|
+
id: "docs_link",
|
|
886
|
+
},
|
|
887
|
+
];
|
|
888
|
+
|
|
889
|
+
return (
|
|
890
|
+
<nav className="flex items-center justify-between p-4">
|
|
891
|
+
<div>Logo</div>
|
|
892
|
+
<ProfilePicMenu
|
|
893
|
+
custom_menu_items={customItems}
|
|
894
|
+
avatar_size="default"
|
|
895
|
+
/>
|
|
896
|
+
</nav>
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
#### Example 4: Single Button Mode
|
|
902
|
+
|
|
903
|
+
```typescript
|
|
904
|
+
// In hazo_auth_config.ini
|
|
905
|
+
[hazo_auth__profile_pic_menu]
|
|
906
|
+
show_single_button = true
|
|
907
|
+
sign_up_label = Get Started
|
|
908
|
+
```
|
|
909
|
+
|
|
910
|
+
When `show_single_button` is `true`, only the "Sign Up" button is shown for unauthenticated users (no "Sign In" button).
|
|
911
|
+
|
|
912
|
+
### Behavior
|
|
913
|
+
|
|
914
|
+
- **Loading State**: Shows a pulsing placeholder while checking authentication status
|
|
915
|
+
- **Unauthenticated**: Shows Sign Up/Sign In buttons (or single button if configured)
|
|
916
|
+
- **Authenticated**: Shows profile picture with dropdown menu
|
|
917
|
+
- **Profile Picture Fallback**: If no profile picture is set, shows user's initials
|
|
918
|
+
- **Logout**: Handles logout action, refreshes auth status, and redirects appropriately
|
|
919
|
+
- **Responsive**: Works well in both navbar and sidebar layouts
|
|
920
|
+
|
|
921
|
+
### Styling
|
|
922
|
+
|
|
923
|
+
The component uses TailwindCSS classes and can be customized with:
|
|
924
|
+
- `className` prop for additional styling
|
|
925
|
+
- `avatar_size` prop for different avatar sizes
|
|
926
|
+
- CSS class names prefixed with `cls_profile_pic_menu_*` for targeted styling
|
|
927
|
+
|
|
928
|
+
Example custom styling:
|
|
929
|
+
|
|
930
|
+
```css
|
|
931
|
+
/* Target specific elements */
|
|
932
|
+
.cls_profile_pic_menu_avatar {
|
|
933
|
+
border: 2px solid #3b82f6;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
.cls_profile_pic_menu_dropdown {
|
|
937
|
+
min-width: 200px;
|
|
938
|
+
}
|
|
939
|
+
```
|
|
940
|
+
|
|
658
941
|
### Local Development (for package contributors)
|
|
659
942
|
|
|
660
943
|
- `npm install` to install dependencies.
|
|
@@ -19,6 +19,11 @@ enable_admin_ui = true
|
|
|
19
19
|
|
|
20
20
|
# PostgREST configuration (uncomment if using postgrest type)
|
|
21
21
|
# postgrest_url =
|
|
22
|
+
|
|
23
|
+
# PostgREST API Key (REQUIRED if PostgREST uses authentication)
|
|
24
|
+
# IMPORTANT: API keys should ONLY be set in environment variables for security
|
|
25
|
+
# Set HAZO_CONNECT_POSTGREST_API_KEY or POSTGREST_API_KEY in your .env file
|
|
26
|
+
# DO NOT put API keys in this config file
|
|
22
27
|
# postgrest_api_key =
|
|
23
28
|
|
|
24
29
|
[hazo_auth__register_layout]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hazo_auth",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"files": [
|
|
5
5
|
"src/**/*",
|
|
6
6
|
"public/file.svg",
|
|
@@ -101,8 +101,8 @@
|
|
|
101
101
|
"@types/react-dom": "^18",
|
|
102
102
|
"better-sqlite3": "^12.4.1",
|
|
103
103
|
"cross-env": "^10.1.0",
|
|
104
|
-
"eslint": "^
|
|
105
|
-
"eslint-config-next": "^
|
|
104
|
+
"eslint": "^9.0.0",
|
|
105
|
+
"eslint-config-next": "^16.0.3",
|
|
106
106
|
"eslint-plugin-storybook": "^10.0.6",
|
|
107
107
|
"jest": "^30.2.0",
|
|
108
108
|
"jest-environment-jsdom": "^29.7.0",
|
|
@@ -52,20 +52,21 @@ export async function POST(request: NextRequest) {
|
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
if (!result.success) {
|
|
55
|
-
logger.
|
|
55
|
+
logger.error("resend_verification_failed", {
|
|
56
56
|
filename: get_filename(),
|
|
57
57
|
line_number: get_line_number(),
|
|
58
58
|
email,
|
|
59
59
|
error: result.error,
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
//
|
|
62
|
+
// Return error response (500) when email sending fails
|
|
63
|
+
// This is a technical error, not a security issue, so we can reveal it
|
|
63
64
|
return NextResponse.json(
|
|
64
65
|
{
|
|
65
|
-
success:
|
|
66
|
-
|
|
66
|
+
success: false,
|
|
67
|
+
error: result.error || "Failed to resend verification email",
|
|
67
68
|
},
|
|
68
|
-
{ status:
|
|
69
|
+
{ status: 500 }
|
|
69
70
|
);
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -155,10 +155,10 @@ export const use_email_verification = <TClient,>({
|
|
|
155
155
|
return true;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
|
|
159
|
-
const hasErrors =
|
|
160
|
-
return
|
|
161
|
-
}, [errors,
|
|
158
|
+
// Only disable if there are active errors
|
|
159
|
+
const hasErrors = !!errors[EMAIL_VERIFICATION_FIELD_IDS.EMAIL];
|
|
160
|
+
return hasErrors;
|
|
161
|
+
}, [errors, isSubmitting]);
|
|
162
162
|
|
|
163
163
|
const handleFieldChange = useCallback((fieldId: EmailVerificationFieldId, value: string) => {
|
|
164
164
|
setValues((previousValues) => {
|
|
@@ -231,7 +231,13 @@ export const use_email_verification = <TClient,>({
|
|
|
231
231
|
}),
|
|
232
232
|
});
|
|
233
233
|
|
|
234
|
-
|
|
234
|
+
let data;
|
|
235
|
+
try {
|
|
236
|
+
data = await response.json();
|
|
237
|
+
} catch (jsonError) {
|
|
238
|
+
// If JSON parsing fails, the response is likely HTML (e.g., error page)
|
|
239
|
+
throw new Error("Server returned an invalid response. Please try again later.");
|
|
240
|
+
}
|
|
235
241
|
|
|
236
242
|
if (!response.ok) {
|
|
237
243
|
throw new Error(data.error || "Failed to resend verification email");
|
|
@@ -38,36 +38,60 @@ export function get_hazo_connect_instance(): HazoConnectAdapter {
|
|
|
38
38
|
try {
|
|
39
39
|
// Get configuration from hazo_auth_config.ini (falls back to environment variables)
|
|
40
40
|
const config_options = get_hazo_connect_config_options();
|
|
41
|
+
const logger = create_app_logger();
|
|
42
|
+
logger.debug("hazo_connect_singleton_attempt", {
|
|
43
|
+
filename: "hazo_connect_instance.server.ts",
|
|
44
|
+
line_number: 38,
|
|
45
|
+
config_options,
|
|
46
|
+
note: "Attempting to get singleton with these options",
|
|
47
|
+
});
|
|
41
48
|
return getHazoConnectSingleton(config_options);
|
|
42
49
|
} catch (error) {
|
|
50
|
+
const logger = create_app_logger();
|
|
51
|
+
const error_message = error instanceof Error ? error.message : "Unknown error";
|
|
52
|
+
logger.error("hazo_connect_singleton_failed", {
|
|
53
|
+
filename: "hazo_connect_instance.server.ts",
|
|
54
|
+
line_number: 45,
|
|
55
|
+
error: error_message,
|
|
56
|
+
error_stack: error instanceof Error ? error.stack : undefined,
|
|
57
|
+
note: "Falling back to manual singleton implementation",
|
|
58
|
+
});
|
|
59
|
+
|
|
43
60
|
// Fallback: Manual singleton implementation if new API fails
|
|
44
61
|
// This should not happen with the updated package, but kept for safety
|
|
45
62
|
if (!hazoConnectInstance) {
|
|
46
|
-
//
|
|
47
|
-
|
|
63
|
+
// Get config options to determine database type
|
|
64
|
+
const config_options = get_hazo_connect_config_options();
|
|
65
|
+
const db_type = config_options.type;
|
|
66
|
+
|
|
67
|
+
// Only initialize SQLite admin service for SQLite databases
|
|
68
|
+
if (db_type === "sqlite" && !isInitialized) {
|
|
48
69
|
initializeAdminService({ enable_admin_ui: true });
|
|
49
70
|
isInitialized = true;
|
|
50
71
|
}
|
|
51
72
|
|
|
52
73
|
// Create the adapter instance (reads from hazo_auth_config.ini)
|
|
74
|
+
// Note: Despite the name, this function supports both SQLite and PostgREST
|
|
53
75
|
hazoConnectInstance = create_sqlite_hazo_connect_server();
|
|
54
76
|
|
|
55
77
|
// Note: Database migrations should be applied manually via SQLite Admin UI
|
|
56
78
|
// or through a separate migration script. The token_service has fallback
|
|
57
79
|
// logic to work without the token_type column if migration hasn't been applied.
|
|
58
80
|
|
|
59
|
-
// Finalize initialization by getting the admin service
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
81
|
+
// Finalize initialization by getting the admin service (only for SQLite)
|
|
82
|
+
if (db_type === "sqlite") {
|
|
83
|
+
try {
|
|
84
|
+
getSqliteAdminService();
|
|
85
|
+
} catch (adminError) {
|
|
86
|
+
const logger = create_app_logger();
|
|
87
|
+
const error_message = adminError instanceof Error ? adminError.message : "Unknown error";
|
|
88
|
+
logger.warn("hazo_connect_instance_admin_service_init_failed", {
|
|
89
|
+
filename: "hazo_connect_instance.server.ts",
|
|
90
|
+
line_number: 0,
|
|
91
|
+
error: error_message,
|
|
92
|
+
note: "Could not get SqliteAdminService during initialization, continuing...",
|
|
93
|
+
});
|
|
94
|
+
}
|
|
71
95
|
}
|
|
72
96
|
}
|
|
73
97
|
|
|
@@ -100,8 +100,10 @@ function get_hazo_connect_config(): {
|
|
|
100
100
|
hazo_connect_section?.postgrest_url ||
|
|
101
101
|
process.env.HAZO_CONNECT_POSTGREST_URL ||
|
|
102
102
|
process.env.POSTGREST_URL;
|
|
103
|
+
// API key must only come from environment variables for security
|
|
104
|
+
// Check multiple possible env var names for compatibility
|
|
103
105
|
const postgrest_api_key =
|
|
104
|
-
|
|
106
|
+
process.env.postgrest_api_key || // hazo_connect package expects this
|
|
105
107
|
process.env.HAZO_CONNECT_POSTGREST_API_KEY ||
|
|
106
108
|
process.env.POSTGREST_API_KEY;
|
|
107
109
|
|
|
@@ -141,10 +143,13 @@ export function create_sqlite_hazo_connect_server() {
|
|
|
141
143
|
}
|
|
142
144
|
|
|
143
145
|
if (config.type === "postgrest") {
|
|
146
|
+
// Ensure we have a value (empty string if not set, for PostgREST instances without auth)
|
|
147
|
+
const apiKey = config.postgrestApiKey || "";
|
|
148
|
+
|
|
144
149
|
return createHazoConnect({
|
|
145
150
|
type: "postgrest",
|
|
146
151
|
baseUrl: config.postgrestUrl!,
|
|
147
|
-
apiKey:
|
|
152
|
+
apiKey: apiKey, // Pass empty string if not set
|
|
148
153
|
});
|
|
149
154
|
}
|
|
150
155
|
|
|
@@ -161,6 +166,8 @@ export function get_hazo_connect_config_options(): {
|
|
|
161
166
|
sqlitePath?: string;
|
|
162
167
|
enableAdminUi?: boolean;
|
|
163
168
|
readOnly?: boolean;
|
|
169
|
+
postgrestUrl?: string;
|
|
170
|
+
postgrestApiKey?: string;
|
|
164
171
|
} {
|
|
165
172
|
const config = get_hazo_connect_config();
|
|
166
173
|
|
|
@@ -173,8 +180,15 @@ export function get_hazo_connect_config_options(): {
|
|
|
173
180
|
};
|
|
174
181
|
}
|
|
175
182
|
|
|
176
|
-
|
|
177
|
-
|
|
183
|
+
if (config.type === "postgrest") {
|
|
184
|
+
return {
|
|
185
|
+
type: "postgrest",
|
|
186
|
+
baseUrl: config.postgrestUrl, // Corrected from postgrestUrl
|
|
187
|
+
apiKey: config.postgrestApiKey || "", // Corrected from postgrestApiKey and ensured string value
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Fallback: return empty object to let it use environment variables
|
|
178
192
|
return {};
|
|
179
193
|
}
|
|
180
194
|
|
|
@@ -245,6 +245,12 @@ export async function resend_verification_email(
|
|
|
245
245
|
error: email_result.error,
|
|
246
246
|
note: "Verification token created but email failed to send",
|
|
247
247
|
});
|
|
248
|
+
|
|
249
|
+
// Return error if email sending failed (this is a technical error, not a security issue)
|
|
250
|
+
return {
|
|
251
|
+
success: false,
|
|
252
|
+
error: email_result.error || "Failed to send verification email",
|
|
253
|
+
};
|
|
248
254
|
}
|
|
249
255
|
}
|
|
250
256
|
|
package/src/middleware.ts
CHANGED
|
@@ -46,6 +46,7 @@ export async function middleware(request: NextRequest) {
|
|
|
46
46
|
"/api/hazo_auth/reset_password",
|
|
47
47
|
"/api/hazo_auth/verify_email",
|
|
48
48
|
"/api/hazo_auth/validate_reset_token",
|
|
49
|
+
"/api/hazo_auth/resend_verification", // Allow resend verification email without auth
|
|
49
50
|
"/api/hazo_auth/me", // Allow /api/hazo_auth/me to be public (returns authenticated: false if not logged in)
|
|
50
51
|
"/hazo_connect/api/sqlite", // SQLite Admin API routes (admin tool, should be accessible)
|
|
51
52
|
"/hazo_connect/sqlite_admin", // SQLite Admin UI page
|