Hotels
How a hotel is modeled, who can do what, and where branding lives.
A hotel is a better-auth organization. Guests are not auth users: they are rows scoped by the hotel id.
Roles
| Role | Can |
|---|---|
owner | everything except deleting, renaming or re-slugging the hotel |
manager | branding, team, guests, offers, export and delete |
staff | read, add and edit guests, read offers |
The app admin (user role admin) sees every hotel: a call can name any hotel with the x-hotel-id header and then acts as its owner. For everyone else the header can only repeat their own hotel, a different one is refused. Roles and their permissions live in packages/auth/src/access.ts.
Hotels are created by the app admin, never self-served. In the dashboard, admins open Hotels (/admin/hotels), fill the name, slug, owner email and optional colors and language, and admin.hotels.create creates the organization with its hotel_settings and emails the owner an invitation (role: owner). The owner joins by accepting it. The same page lists every hotel (admin.hotels.list) with guest count, owner count and a health badge.
Deleting a hotel and changing its name or slug only go through the admin procedures. admin.hotels.update takes name and slug (same format as on create, refused with CONFLICT when another hotel has it), and the admin hotel page asks to confirm a new slug, since every QR code already printed with the old one stops working. admin.hotels.remove deletes. better-auth's own /api/auth/organization/delete is off and /api/auth/organization/update refuses name and slug, so an owner or manager can't do either.
Accounts are never self-served either. Sign up over http only works for an email with a pending, unexpired invitation (password, GitHub and magic link alike, checked in the user.create.before hook of packages/auth). Accounts made server side (the ADMIN_EMAIL admin, the demo seed, signUp() in tests) and the admin plugin's create-user skip the check.
App admins can ban a user from the Users page: it signs them out everywhere and blocks sign in until they are unbanned. You cannot ban yourself or another app admin. Every ban and unban is in the audit log.
A suspended hotel is closed: resolveHotel refuses its team with FORBIDDEN and no automation (welcome, birthday, holidays, survey, campaigns) sends for it. The owner keeps the read-only guest exports (guests.export, guests.exportAll, guests.exportCsv, built on hotelExportProcedure). The app admin keeps full access.
Health is the first problem found, by hotelHealth in packages/common/src/hotel.ts: suspended, no-owner (invitation not accepted yet), no-guests, quiet (no new guest for 14 days), else healthy.
Branding is config
hotel_settings has one row per hotel, created with the organization: display name, logo key, two colors, reply-to, default language (en, fr, ar, default fr), timezone (default Africa/Tunis), Google review link, manager WhatsApp and Telegram contacts. Owners and managers edit it with hotel.update and the logo with hotel.logo.* on the Hotel page, split into sections that each save only their own fields: Brand (logo, name, two colors with the contrast warning and a live preview, guest language), Messaging (reply-to, address, timezone, the fixed quiet hours), Alerts (Telegram link and the low score threshold) and Google review. Staff see the page read only. The manager WhatsApp and Telegram contact columns are no longer edited there: alerts go to the linked Telegram chat, else by email. Plan, status and pilot end date are admin.hotels.update only.
Hotel scoped procedures
Use hotelProcedure for anything about a hotel. It puts context.hotel (hotelId, role, superAdmin) on the call, and every query filters on context.hotel.hotelId, never on an id from the input. Narrow it with can({ guest: ["export"] }). It refuses a suspended hotel, so only a read-only export should use hotelExportProcedure instead.
Dashboard: landing in a hotel
A hotel user's session starts with their oldest membership as the active hotel, so they land on /guests without picking anything. Someone in several hotels gets a switcher at the top of the sidebar (hotel.mine lists their hotels, switching calls better-auth setActive). A user without a hotel sees an empty state, never another hotel's data.
The guest list (/guests) reads guests.list, which only returns the active hotel's guests. Filters live in the url (q, consent, source, language, returning, page), so a search can be shared. One search box matches the name, the email or the phone digits (20 123 456 finds +21620123456). consent=none means no email and no WhatsApp consent, returning=1 keeps guests with two visits or more, and each row carries its visit count for the returning badge. On phones each guest is a card, from md up it is a table.
The guest page (/guests/[id]) shows the profile, consent per channel with its log, stays, offers used, survey answers (guests.activity) and messages. Staff with guest.update edit the details at /guests/[id]/edit and change a consent after a confirm: withdrawing is logged as a guest request, granting shows the exact wording in the guest's language and is logged as staff. Deleting a guest asks to type their name.
Adding guests: quick add and CSV import
/guests/new is the front desk form: name and phone, optional email, and two consent checkboxes the staff tick only for what the guest said (source staff), each showing the exact wording in the guest's language. It is built for a phone: one column, 44px targets, and it stays ready for the next guest after each save.
/guests/import (owners and managers, the guest.import permission) takes a CSV of up to 1000 rows or 1 MB. Commas and semicolons both work. The hotel matches its columns to name, phone, email, birthday, language and consent, then guests.import checks every row on its own: a bad row never blocks the others and comes back in a downloadable error report. A phone that already exists merges into that guest with the same upsertGuest rules as every other source, and a CSV "no" never withdraws an existing "yes". Source is always csv.
Consent from a CSV is deliberately strict: it is only granted when the consent cell is an explicit yes (true, yes, oui, 1) and the hotel ticked the confirmation that it holds that consent. It covers WhatsApp (for numbers that can take it) and email (when there is an address), is logged like any other consent event with source csv, and the import itself is written to the audit log with counts only.
Isolation is tested
One hotel can never read, change, export or delete another hotel's guests. packages/orpc/src/routers/tests/isolation.test.ts calls every guest procedure of hotel A with an id of hotel B (always a plain "not found"), checks lists, search and the hotel export, the x-hotel-id header, removed members, and fails when a new guest procedure is added without being covered. apps/e2e/tests/isolation.spec.ts repeats the core of it over http against the running api.
Guest procedures (guests.*): list, get, create (adds or merges by phone), update, setConsent, consentHistory, export (one guest), exportAll (the hotel), remove. Export and delete need the owner or manager role, and both write an audit row without personal data.
Metrics
The Metrics page (/metrics, linked from the dashboard home) answers "what did the guest list bring this period" for 7, 30 or 90 days, all scoped to the active hotel (metrics.get):
- Guests captured, as bars per day (7 days) or per week (30, 90), split by source. Plain markup, no chart library
- Consent rate for WhatsApp and email among the guests captured in the period
- Messages sent and the share delivered, from the
messagestable - Offer codes sent in the period and how many of those same codes were redeemed, so a redemption of an older code never inflates the rate
- Reviews requested (guests who tapped the Google review link after the survey) and the survey score with the number of unhappy answers (0 to 6), from
survey_responses. With no answers yet the cards show a dash and say so, the page never invents a number