Repository navigation
Conversation
added 8 commits
November 17, 2026 14:30
The pool passed QueuePool to an async engine and built its URL from settings fields that do not exist, so initialization always failed. Every revenue request then silently fell back to hardcoded mock totals keyed only by property id: Sunset's prop-001 showed 1000.00 instead of 2250.00, and tenants sharing a property id saw the same numbers. Use the default async pool with settings.database_url, share one pool instead of creating one per request, and let DB errors surface instead of returning fake data.
Property ids are only unique per tenant (prop-001 exists for both
Sunset and Ocean), but the cache key was revenue:{property_id}. Whoever
loaded a property first had their totals served to the other tenant
for 5 minutes.
Amounts are stored with 3 decimals. The API converted the Decimal sum to float and the frontend re-rounded it with Math.round, so totals could drift by a cent. Round once on the server with ROUND_HALF_UP, send the total as a decimal string, and format it without float math. Also removes the hardcoded "+12%" trend badge, which was not based on any data.
- The backend fell back to a "default_tenant" when the user had none; now it returns 403. - The frontend sent an X-Simulated-Tenant header and hardcoded the property list (including other tenants' properties). Properties now come from GET /dashboard/properties, scoped to the user's tenant. - Requesting another tenant's property returns 404 instead of 0.00. - Ignore stale responses when switching properties quickly.
Any user not in the hardcoded email list was assigned tenant-a and could see Sunset's revenue. Read tenant_id from the verified token (app_metadata or root claim; never user-editable user_metadata), then the known demo users, and otherwise return no tenant.
calculate_monthly_revenue was a stub returning 0, and its query used UTC month boundaries: a booking at 2024-02-29 23:30 UTC in Paris (already March 1 locally) would land in February, giving Sunset 1000.00 for March on Beach House Alpha instead of 2250.00. Convert each check-in with check_in_date AT TIME ZONE p.timezone before comparing it with the month boundaries, and scope the query by tenant.
The storage health check treated plain-string values (version marker, language, ...) as corruption and cleared localStorage, auth token included, which could log the user out. Skip non-JSON values and always preserve the auth token.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the three reported issues and one extra bug I found. Each fix is a separate commit.
Fixes
Database never connected: the connection settings were wrong, and an error
handler hid the failure by showing fake numbers. Fixed the connection and removed
the fake data. Sunset's prop-001 now shows 2,250.00 instead of 1,000.00.
Companies seeing each other's data: the cache was keyed by property ID only,
and both companies have a
prop-001. The cache key now includes the company. Thecompany now comes only from the login token, and each company sees only its own
properties.
Wrong March totals (timezone): a booking on 29 Feb at 23:30 UTC is already
1 March in Paris. Monthly revenue now uses each property's own timezone.
Totals off by a cent: money was converted to float and rounded twice. It now
stays exact (Decimal), is rounded once, and is sent as text.
Logged out on refresh: a storage cleanup deleted the login token. The token is
now always kept.
Testing
Tested as both clients: every total matches the database, each company sees only its
own properties, another company's property returns 404, and users stay logged in
after refreshing.