Skip to content

Synchronous requests to edge functions, roles for UI, #58

Open
Spotchi wants to merge 6 commits intoCommonsHub:mainfrom
Spotchi:feat/sync_requests
Open

Synchronous requests to edge functions, roles for UI, #58
Spotchi wants to merge 6 commits intoCommonsHub:mainfrom
Spotchi:feat/sync_requests

Conversation

@Spotchi
Copy link
Collaborator

@Spotchi Spotchi commented Aug 8, 2025

This pull request introduces a major architectural change by migrating all booking and request operations from database triggers to direct edge function calls from the frontend. This centralizes business logic, improves security, and simplifies error handling. Effectively, this means the https://github.com/CommonsHub/bookingsystem-dbtrigger repo is no longer useful. The frontend hooks for creating and approving bookings and requests have been refactored to use the new edge function approach, and user role management has been enhanced to support role-based access control (RBAC). Several UI and localization improvements are also included.

Edge Function Migration and Centralization:

I have performed this refactor as there are less failure points (1 edge function instead of a DB trigger + an edge function with ad hoc authentication) and it is much easier to debug.

  • Added EDGE_FUNCTION_MIGRATION.md to document the migration from database triggers to edge function calls, outlining the new architecture, benefits, migration steps, and troubleshooting.
  • Refactored frontend hooks (useCreateBooking, useCreateRequest, useApprovalOperations) to send data directly to the edge function for all create and approve operations, removing reliance on direct Supabase table writes and triggers. [1] [2] [3] [4] [5] [6] [7]

Role-Based Access Control (RBAC):

  • Updated AuthProvider to fetch user roles from the user_roles table and include them in the user context, enabling RBAC throughout the app. [1] [2]
  • Refactored admin checks in RequestProvider to use a new RBAC utility (isAdmin) instead of email domain heuristics. [1] [2]

UI and Localization Improvements:

  • Added a new "Mark as Completed" translation key to English, German, French, and Dutch locale files for improved UI consistency. [1] [2] [3] [4]
  • Updated Header to only show the "ICS Preview" button to users who have booking approval permissions, using a new helper (canUserApproveBookings). [1] [2]

Other Changes:

  • Added explicit packageManager field to package.json for reproducible builds.

These changes modernize the system by centralizing logic, improving security and maintainability, and laying the groundwork for future enhancements.

@netlify
Copy link

netlify bot commented Aug 8, 2025

Deploy Preview for chb-booking-system-blue-ocean-happy ready!

Name Link
🔨 Latest commit 62c5184
🔍 Latest deploy log https://app.netlify.com/projects/chb-booking-system-blue-ocean-happy/deploys/6895ca43841c0900088de438
😎 Deploy Preview https://deploy-preview-58--chb-booking-system-blue-ocean-happy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@friedger
Copy link
Contributor

Can you elaborate how this will work with nostr in the future?

I see the benefits, however, the server based approach moves us further away from the event based approach of nostr.

Centralized logic on one server means less openness and less opportunities to build on top of it.

@Spotchi
Copy link
Collaborator Author

Spotchi commented Sep 27, 2025

This was mostly because it is less code.

I think either approach doesn't work with NOSTR in any case.
The pre-PR situation is that the supabase API is called, and that triggers an edge function that sends an email, updates calendar and publishes to NOSTR using the application's npub.
The post-PR situation would be that we call the edge function directly.

To move this to a NOSTR-backend and do it properly, we should either:

  • have a NOSTR login for the user (through nsec or NIP-46) and sign events on the client-side
  • create NIP-46 sessions for the user and sign events on their behalf in the backend (requests application will manage its connection keys)

@friedger
Copy link
Contributor

To create an open system, I see the current supabase DB as a placeholder for the nostr network, where users store their reuqests and comments. Then we have edge functions that can work with this data.

I think users should not interact with the backend directly to keep the system open.

@Spotchi
Copy link
Collaborator Author

Spotchi commented Sep 30, 2025

I agree with the principle, but don't see how much more open a Database trigger than an API call. If this is deemed unnecessary we can can this PR, as it doesn't move towards more openness, only developer-friendliness

@friedger
Copy link
Contributor

Api calls depends on a single implementation, nostr storage only on the nostr node.

To can or not to can?

How would the migration to nostr work? How does the backend/edge functions would need to change?

@Spotchi
Copy link
Collaborator Author

Spotchi commented Oct 1, 2025

No more supabase db trigger or edge function.
A user publishes event updates to Nostr, and there is probably a daemon process listening to nostr relays to sync google calendar and send email notifications

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.

2 participants