Events
Subscribe functions to lifecycle events to execute code when specific actions occur.
Overview
Events allow you to trigger functions automatically when certain actions happen in your application. Subscribe functions to events like user creation, data updates, or custom triggers to build reactive workflows.
Concepts
Event
A notification that something has occurred in your application. Events have a type (e.g., POST_USER_CREATE) and carry data about what happened.
Event Subscription
A connection between an event and a function. When the event fires, all subscribed functions are executed.
Pre/Post Events
- Pre Events: Fire before an action completes (can block or modify)
- Post Events: Fire after an action completes (for side effects)
View Events
- Navigate to your App in the Dashboard.
- Click Events in the sidebar.
- View all available event types with:
- Event Name: The event type
- Subscribers: Number of subscribed functions
- Description: What triggers this event
Available Event Types
User Events
| Event | Description |
|---|---|
PRE_USER_CREATE | Before a new user is created |
POST_USER_CREATE | After a new user is created |
PRE_USER_UPDATE | Before a user is updated |
POST_USER_UPDATE | After a user is updated |
PRE_USER_DELETE | Before a user is deleted |
POST_USER_DELETE | After a user is deleted |
Authentication Events
| Event | Description |
|---|---|
POST_LOGIN | After successful login |
POST_LOGOUT | After user logout |
POST_PASSWORD_RESET | After password reset |
Data Events
| Event | Description |
|---|---|
PRE_RECORD_CREATE | Before a record is created |
POST_RECORD_CREATE | After a record is created |
PRE_RECORD_UPDATE | Before a record is updated |
POST_RECORD_UPDATE | After a record is updated |
PRE_RECORD_DELETE | Before a record is deleted |
POST_RECORD_DELETE | After a record is deleted |
Subscribe a Function
- Navigate to Events in your app.
- Find the event you want to subscribe to.
- Click the event card to expand it.
- Click Subscribe Function.
- Select the function to subscribe.
- Click Subscribe.
Subscribe to PRE_* events when you need to validate or modify data before an action. Subscribe to POST_* events for notifications, logging, or side effects.
View Event Subscribers
- Navigate to Events in your app.
- Click on an event card.
- View the list of subscribed functions:
- Function Name: The subscribed function
- Status: Active or Inactive
- Subscribed Date: When it was subscribed
Unsubscribe a Function
- Navigate to Events in your app.
- Click on the event.
- Find the function in the subscribers list.
- Click Unsubscribe.
- Confirm the action.
Event Handler Structure
When a function is triggered by an event, it receives event data:
def handler(request, context):
# Get event data
event_type = context.event_type
event_data = context.event_data
# Event data contains details about what happened
user_id = event_data.get("user_id")
changes = event_data.get("changes")
# Perform your logic
if event_type == "POST_USER_CREATE":
send_welcome_email(event_data["email"])
return {"status": "ok"}
Pre-Event Handlers
Pre-event handlers can modify or block actions:
def handler(request, context):
event_data = context.event_data
# Validate user data before creation
if not is_valid_email(event_data["email"]):
return {
"allow": False,
"message": "Invalid email address"
}
# Allow the action to proceed
return {"allow": True}
Configuration
Subscription Settings
| Setting | Description |
|---|---|
| Function | The function to execute |
| Priority | Execution order (lower = first) |
| Active | Enable/disable the subscription |
Best Practices
- Use POST events for side effects: Logging, notifications, analytics
- Use PRE events for validation: Input validation, authorization checks
- Keep handlers fast: Event handlers should complete quickly
- Handle errors gracefully: Don't let handler errors break the main flow
- Avoid infinite loops: Don't trigger events that call the same handler
Limits
| Resource | Limit |
|---|---|
| Subscriptions per event | 10 |
| Handler timeout | 10 seconds |
| Event payload size | 1 MB |
Need higher limits? Contact support to discuss your requirements.
Troubleshooting
Event handler not triggering
Problem: A subscribed function isn't being called when the event fires.
Solution:
- Verify the function is Active.
- Check the subscription is Active.
- Confirm the event type matches what you're triggering.
- Check function execution history for errors.
Pre-event blocking unexpectedly
Problem: Actions are being blocked when they shouldn't be.
Solution:
- Review the pre-event handler code.
- Check the handler is returning
{"allow": True}for valid cases. - Add logging to identify the blocking condition.
Handler receiving wrong data
Problem: Event data doesn't contain expected fields.
Solution:
- Log the full event_data to see what's available.
- Check the event type documentation for expected fields.
- Verify you're subscribing to the correct event type.
Related
Last Updated: January 2025