Skip to content

PHP API, Hooks & CLI

Resolve the module cleanly from any ProcessWire context with Account::requireInstance($wire):

<?php namespace ProcessWire;
use Totoglu\Account\Flow\AccountRequest;
$account = Account::requireInstance($wire);
$summary = $account->accountSummary($user);
$profile = $account->profile($user);
$props = $account->flowProps('login');
$html = $account->render('login');
$result = $account->handle(new AccountRequest(action: 'profile_update', payload: ['display_name' => 'Claire B.']));
$hasSudo = $account->hasActiveSudo();
$invitation = $account->issueInvitation('[email protected]', ['role' => 'member', 'ttl' => 86400]);
$saved = $account->saved();
$notifications = $account->notifications();
$inbox = $account->inbox();
Hook Arguments & Return Timing What It Does
Account::handle (AccountRequest $request): AccountResult Before / After Processes any authentication, profile, MFA, or privacy AccountRequest and returns an AccountResult.
Account::render (string $screen = 'login', array $options = []): string Before / After Renders classic server-rendered HTML forms for auth and self-service account screens.
Account::renderInertia (string $screen = 'login', array $extraProps = [], string $currentUrl = ''): string Before / After Renders Inertia-powered React screens for /auth/* and /account/* routes.
Account::flowProps (string $screen, array $overrides = []): array After Builds the shared screen view model across all auth and account stages; mutate $event->return to inject site-wide props.
Account::forwardWebhook (string $event, array $payload): void After Forwards account.* lifecycle webhook payloads to Headless or custom transports.
Account::resolveBlueprint (string $type, array $definition): array After Customizes internal account-* Entries blueprints before registration.
Account::beforeNotificationSend (string $templateHandle, NotificationTarget $target, array $data): void Before Inspects or adjusts notification template data or targets right before multi-channel dispatch.
Account::afterNotificationSend (DispatchResult $result): void After Reacts to completed email, SMS, webhook, or inbox notification deliveries.
Account::resolveSavedItems (string $targetType, array $targetIds, array $resolved = [], ?User $viewer = null): array After Hydrates custom saved-item target types alongside SavedItemResolverInterface cards.
Account::translations (): array After Overrides or extends frontend /auth/* and /account/* UI translation bundles.
ProcessAccount::translations (): array After Overrides or extends admin Setup -> Account React workspace strings.
PageSavedItemResolver::extractFirstImageUrl (Page $page): string After Customizes which thumbnail image URL is resolved for saved ProcessWire pages.
site/ready.php
<?php
declare(strict_types=1);
namespace ProcessWire;
// 1. Inject brand metadata into every /auth/* and /account/* screen
$wire->addHookAfter('Account::flowProps', function (HookEvent $event): void {
$props = (array) $event->return;
$props['conciergeEmail'] = '[email protected]';
$event->return = $props;
});
// 2. Append extra template variables right before sending an invitation email
$wire->addHookBefore('Account::beforeNotificationSend', function (HookEvent $event): void {
$templateHandle = (string) $event->arguments(0);
$data = (array) $event->arguments(2);
if ($templateHandle === 'member-invitation') {
$data['seasonLabel'] = 'Summer Charter Season';
$event->arguments(2, $data);
}
});
// 3. Hydrate custom yacht saved items in the Member Hub
$wire->addHookAfter('Account::resolveSavedItems', function (HookEvent $event): void {
$targetType = (string) $event->arguments(0);
$targetIds = (array) $event->arguments(1);
if ($targetType !== 'yacht') {
return;
}
$resolved = (array) $event->return;
foreach ($targetIds as $id) {
$resolved[(string) $id] = [
'id' => (string) $id,
'title' => 'Yacht #' . $id,
'url' => '/fleet/' . $id . '/',
];
}
$event->return = $resolved;
});

Run all commands via php vendor/bin/wire <command>:

Command Options & Arguments Purpose
account:doctor --json Audits blueprints, managed SQL tables, starter templates, routes, and security flags.
account:scaffold:user -f/--field, --style=card|default|inline, --allow-user-template, --activate, --dry-run, --json Opt-in scaffolder that attaches @fieldset:account-profile to the ProcessWire user template and optionally switches profile_source to user.
account:invite <email>, -r/--role, --ttl, --no-mail, --dry-run, --json Creates a single-use member invitation link with optional role assignment and expiry TTL.
account:sessions -u/--user, --revoke-all, --dry-run, -f/--force, --json Lists or force-revokes persistent account-sessions device tokens.
account:notify-test <template>, --email, --phone, --user-id, --webhook, --locale, --channel, --data, --queue, --sync, --json Dispatches a test notification through a specific template and channel with custom JSON payload data.
account:prune -d/--days, --dry-run, -f/--force, --json Prunes expired challenges, revoked sessions, and aged delivery/audit records (AccountPruneTask runs daily at 03:30).
  • Queue Worker & Daily Prune Cron: Run php vendor/bin/wire queue:work --tries=3 --sleep=3 for queued notifications and schedule * * * * * php vendor/bin/wire schedule:run so AccountPruneTask cleans expired challenges and revoked sessions daily at 03:30.
  • Log Channels: Inspect Setup -> Logs -> account-sms for SMS gateway delivery diagnostics and Setup -> Logs -> account-audit for security events.
  • Secrets via $env:VAR: Reference OAuth client secrets, SMS credentials, and webhook signing secrets using $env:ACCOUNT_WEBHOOK_SECRET (encrypted at rest via SecretBox when stored directly).
  • ProCache Exclusion: Always exclude /auth/* and /account/* from full-page HTML caches.

Outbound Webhook Payload & HMAC Verification

Section titled “Outbound Webhook Payload & HMAC Verification”

Outbound notification webhooks include X-Account-Timestamp, X-Account-Batch, and X-Account-Signature (sha256=<hex>):

{
"event": "account.member.invited",
"timestamp": "2026-06-15T12:00:00Z",
"data": {
"email": "[email protected]",
"role": "member"
}
}

Verify the signature on your receiver using constant-time comparison:

<?php
declare(strict_types=1);
$rawBody = file_get_contents('php://input') ?: '';
$timestamp = $_SERVER['HTTP_X_ACCOUNT_TIMESTAMP'] ?? '';
$received = $_SERVER['HTTP_X_ACCOUNT_SIGNATURE'] ?? '';
$expected = 'sha256=' . hash_hmac('sha256', $timestamp . '.' . $rawBody, (string) getenv('ACCOUNT_WEBHOOK_SECRET'));
$isValid = hash_equals($expected, $received);

Frontend Styling (CSS Variables) & Browser Events

Section titled “Frontend Styling (CSS Variables) & Browser Events”
  • CSS Custom Properties: Override theme tokens on :root to match your storefront palette without editing module CSS: --account-bg, --account-fg, --account-surface, --account-muted, --account-muted-fg, --account-border, --account-primary, --account-primary-fg, --account-danger.
  • Browser CustomEvent: Listen for account:saved:changed on window whenever a visitor toggles a favorite/saved item via AccountFrontend.js to sync header counters or badges.

Superuser Cannot Sign In Through /auth/login

Section titled “Superuser Cannot Sign In Through /auth/login”
  • By design, AccountGuard blocks superuser and guest accounts on public /auth/* forms so administrative credentials cannot be targeted from the frontend. Sign in as a superuser through the ProcessWire admin URL instead.

WebAuthn Passkeys Fail in Local Development

Section titled “WebAuthn Passkeys Fail in Local Development”
  • Browsers require a secure context (https:// or localhost) for WebAuthn Passkeys. Use HTTPS on your local domain (for example https://processwire.test) and verify the Relying Party ID matches the active hostname.

Guest Saved Items Do Not Persist After Sign-In

Section titled “Guest Saved Items Do Not Persist After Sign-In”
  • Confirm cookies are accepted on your domain and that dist/AccountFrontend.js is enqueued ($account->getFrontendScriptAssets()). On successful sign-in, Account automatically merges the HMAC-signed account_saved cookie into entries_tbl_account_saved_items.

Outbound Notification Webhooks Are Rejected

Section titled “Outbound Notification Webhooks Are Rejected”
  • WireHttpTransport blocks private, loopback, and link-local IP ranges (SSRF protection). Test against a public HTTPS endpoint or use $account->fakeNotifications() in automated tests.

Next steps