hazo_auth 1.0.1 → 1.0.2
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/package.json +1 -1
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.
|