Skip to content

Conversation

@Maphikza
Copy link
Member

Backend API Migration and Personal Mode Implementation

Summary

This PR implements a complete migration to the new unified backend API structure and adds full support for public, only-me, and
invite-only relay modes. The changes provide a robust foundation for the new access control system with proper NPUB handling and
mode-specific UI flows.

Key Features Implemented

✅ Public Mode

  • Forced Permissions: Automatically sets read/write to "all_users"
  • UI Behavior: Hides user management, shows tier configuration
  • Default Tiers: Basic (100MB), Standard (500MB), Plus (1GB)

✅ Only-Me Mode

  • Relay Owner Management: Dedicated API endpoints for single owner
  • NPUB Conversion: Proper hex ↔ npub conversion using nip19
  • Owner UI: Clean interface for setting/updating/removing relay owner
  • Forced Permissions: Write locked to "only_me", read configurable

✅ Invite-Only Mode

  • User Management: Add/remove users with tier assignment
  • Pagination: Support for large user lists (20 users per page)
  • Forced Permissions: Write locked to "allowed_users", read configurable
  • Default Tiers: Member (5GB), VIP (50GB), Unlimited

Technical Changes

API Migration

  • Unified Endpoints: Migrated from separate read/write APIs to unified user management
  • REST Compliance: Proper HTTP methods (GET, POST, DELETE)
  • NPUB Support: Full bech32 encoding/decoding with nostr-tools
  • Error Handling: Comprehensive logging and user feedback

Type System Updates

  • New Mode Types: 'only-me' | 'invite-only' | 'public' | 'subscription'
  • Permission Types: 'all_users' | 'paid_users' | 'allowed_users' | 'only_me'
  • Unified User Model: Single AllowedUser interface replacing separate read/write models
  • Mode Configurations: Automatic permission validation and enforcement

UI Components

  • Mode Selector: Updated 2x2 grid with proper mode descriptions
  • Permissions Config: Dynamic UI based on mode with forced permission indicators
  • Relay Owner Config: New component for only-me mode owner management
  • User Management: Enhanced table with tier assignment and pagination

Backend Integration Status

Mode Frontend Status Backend Status Notes
Public ✅ Complete ✅ Working Fully functional
Only-Me ✅ Complete ✅ Working Uses /api/admin/owner endpoints
Invite-Only ✅ Complete ⏳ Pending Waiting for /api/allowed/add and /api/allowed/remove
Subscription ⏳ Future ⏳ Future Next phase

Files Changed

Core API

  • src/api/allowedUsers.api.ts - Complete rewrite for new backend structure
  • src/types/allowedUsers.types.ts - Updated types and mode configurations

Components

  • src/components/allowed-users/components/ModeSelector/ - Updated mode names and descriptions
  • src/components/allowed-users/components/PermissionsConfig/ - Mode-based permission enforcement
  • src/components/allowed-users/components/NPubManagement/ - Unified user management
  • src/components/allowed-users/components/RelayOwnerConfig/ - New - Owner management for only-me mode
  • src/components/allowed-users/layouts/AllowedUsersLayout.tsx - Conditional UI rendering

State Management

  • src/hooks/useAllowedUsers.ts - Updated hooks for new API structure
  • src/store/slices/allowedUsersSlice.ts - State management updates

Testing Notes

What Works Now

  • Public Mode: Switch to public mode, save settings
  • Only-Me Mode: Set relay owner, update owner, remove owner
  • Mode Transitions: Automatic permission enforcement when switching modes
  • NPUB Validation: Proper format validation and conversion

What Needs Backend Support

  • Invite-Only User Management: Adding/removing users (endpoints not implemented)
  • User List Loading: Getting paginated user lists (endpoint not implemented)

Migration Notes

Breaking Changes

  • API Endpoints: Old read/write endpoints no longer used
  • Data Structure: User permissions now tier-based instead of boolean flags
  • Mode Names: Updated from personal/exclusive/free/paid to only-me/invite-only/public/subscription

Maphikza added 2 commits June 28, 2025 15:09
- Update API endpoints to match new unified backend structure
- Add relay owner management API endpoints for only-me mode
- Implement nip19 encoding/decoding for proper NPUB format handling
- Update types to support new mode structure and permissions
- Replace old read/write NPUB management with unified user system
- Add proper validation and error handling for mode transitions
- Change endpoint URLs from /api/allowed-users to /api/allowed/users
- Use proper REST methods: POST for add, DELETE for remove
- Maintain NPUB format for backend compatibility
- Add comprehensive logging for debugging backend communication
- Ready for backend team to implement missing endpoints
Maphikza added 8 commits June 29, 2025 18:52
- Detect wallet service unavailable errors and show clear user message
- Explain Bitcoin payment requirement and wallet service dependency
- Automatically revert to previous mode when subscription mode fails
- Prevent UI from getting stuck in inconsistent state
- Increase error message duration for better readability
- Implement wallet health check API integration with /panel-health endpoint
- Add real-time wallet status indicators with proper theming
- Fix transaction size calculation spamming by optimizing useEffect dependencies
- Add request deduplication to prevent multiple simultaneous API calls
- Remove wallet lock requirement (healthy + synced = ready to transact)
- Improve authentication retry logic for both health checks and transaction calculations
- Add proper error handling and user feedback for wallet connectivity issues
- Replace unescaped quotes with " entities in error message text
- Resolves react/no-unescaped-entities warning
- Fix TiersConfig radio button alignment and syntax error
- Update Alert component styling for consistent dark theme
- Add ForcedSelectWrapper for better disabled state styling
- Improve radio group layout with proper click handling
- Fix card positioning and interaction in tier selection
Prevents saving "only-me" mode when no relay owner is set by:
- Adding owner existence check before mode save
- Showing clear error messages to guide users
- Blocking invalid saves to maintain system integrity
- Remove redundant nested card wrapper in PermissionsConfig
- Remove unnecessary permission type explanations
- Fix active tier colors using CSS variables for dark theme compatibility
- Replace hardcoded colors with theme-aware variables
- Fix payment notifications read-all endpoint by sending {} instead of undefined
- Remove unused AddKindForm component and related props
- Clean up KindsSection interfaces and component structure
- Update layout components to remove onAddKind prop references
- Add .eslintignore to exclude build/, node_modules/, and generated files
- Update lint script to only target src/ directory instead of all files
- Resolves 555+ false lint errors from scanning compiled/minified code
@f7f376a1fcd0d0e11a10ed1b6577c9 f7f376a1fcd0d0e11a10ed1b6577c9 merged commit ef12264 into main Jul 3, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants