PelcroUserLoaded
Fired when user data is loaded or updated
Overview
Fired whenever user data is loaded or updated. This event fires frequently - after login, registration, profile updates, and session refresh. Use it to keep your UI in sync with user state.
Triggered By
This event fires after any successful user operation:
| Method | When |
|---|---|
Pelcro.user.register() | After registration |
Pelcro.user.login() | After login |
Pelcro.user.idpLogin() | After SSO login |
Pelcro.user.update() | After profile update |
Pelcro.user.refresh() | After session refresh |
Pelcro.user.authenticate() | After token authentication |
Pelcro.user.verifyEmailToken() | After email verification |
Pelcro.user.verifyLoginToken() | After passwordless login |
Pelcro.user.uploadProfilePicture() | After picture upload |
Pelcro.user.removeProfilePicture() | After picture removal |
Pelcro.user.resendEmailVerification() | After resending verification |
Event Detail
The event.detail object contains the complete user object:
| Property | Type | Description |
|---|---|---|
id | number | User's unique identifier |
email | string | User's email address |
first_name | string | User's first name |
last_name | string | User's last name |
auth_token | string | JWT authentication token |
email_verified | boolean | Whether email is verified |
subscriptions | array | User's active subscriptions |
memberships | array | User's memberships |
addresses | array | User's saved addresses |
orders | array | User's order history |
metadata | object | Custom metadata fields |
Example
document.addEventListener('PelcroUserLoaded', (event) => {
const user = event.detail;
// Update UI with latest user data
updateUserDisplay({
name: `${user.first_name} ${user.last_name}`,
email: user.email,
avatar: user.profile_photo
});
// Update subscription status
if (user.subscriptions?.length > 0) {
showSubscriberBadge();
}
});Boot-Time vs. User-Action
This event can fire in two contexts:
- During boot - If user has a valid session, fires when session is restored
- After user action - Fires after any method that updates user data
To distinguish, check if PelcroBootComplete has already fired.
Related
- Events Overview - All available events
- PelcroUserLoggedIn - Specific to login actions
- PelcroUserUpdated - Specific to profile updates
Updated 1 day ago
