Skip to Content

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

RoleCan
ownereverything except deleting, renaming or re-slugging the hotel
managerbranding, team, guests, offers, export and delete
staffread, 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.

The dashboard only mirrors these (apps/dashboard/lib/viewer.ts), the api is what refuses:

  • the menu, command palette and phone tabs list the hotel pages the role on the hotel on screen can open. Staff do not see Import, Campaigns, Holidays, Hotel, Guest data, Activity log or Usage
  • with no hotel on screen, only Home, Inbox and Account stay (plus the platform pages for the app admin)
  • a staff member typing a campaign address gets "not for your role"
  • the platform pages (/admin/*, /users, /audit-log) are a 404 for everyone but the app admin (requireAdmin)
  • a page whose data could not be loaded shows the error screen: prefetch what a useSuspenseQuery reads with fetchQuery, which throws, never prefetchQuery

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 accept page reads the invitation with me.invitation, not better-auth's getInvitation, which refuses once the inviter has left the hotel (the admin leaves as soon as the invite is made). An invitation is only good while its sender is a member of the hotel or an app admin, and is not banned (inviterMayInvite in packages/auth, checked on read and on accept). The same page lists every hotel (admin.hotels.list) with guest count, owner count and a health badge.

Pending invitations, in the dashboard:

  • The admin's hotel page (/admin/hotels/<id>) can invite an owner to an existing hotel, and on each pending invitation send it again, revoke it or copy its link (admin.hotels.invitations.create, resend, revoke). These do not go through better-auth, which only serves members of the hotel. Sending again restarts the 48 hours (INVITATION_TTL_SECONDS), also for an expired invitation, and is refused when the sender no longer counts (inviterMayInvite): revoke it and invite again. When no email left, the page says so and the link is sent by hand. Inviting an owner does not remove the current one, and someone already in the hotel is refused.
  • /team has the same three actions for owners and managers. A manager cannot copy an owner's link.
  • Creating, sending again and revoking are audited from both places (hotel.invitation-create, -resend, -revoke) with ids only. Copying a link is not recorded.

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. Printed /q/<code> codes keep working (short links), but links shared by hand and /h/<old slug> codes printed before short links stop 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 is checked in the user.create.before hook of packages/auth. It always needs a pending, unexpired invitation for that email whose sender still counts (inviterMayInvite), and never works for a demo address. On top of that, knowing an invited address is not enough:

Sign up pathWhat proves the person was invited
Email and passwordThe invitation id, sent in the x-invitation-id header. The dashboard takes it from next=/accept-invitation/<id>, so the invitee has to start from the invitation link (it leads to sign in, then Create an account). Opening /sign-up directly is refused
Magic linkThe link itself was delivered to the address, no id needed
GitHubGitHub reports the address as verified, no id needed. An unverified address is refused unless the request carries the id, which the dashboard redirect flow does not
Accept page, existing accountNo sign up: the user signs in and accepts

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.

Pilot success. The admin Platform overview (/admin/overview) tracks the pilot with counts only, no guest data. Platform wide: guests captured, the consent rate and how many open hotels were active in the last 7 days. Per open (not suspended) hotel, most guests first: guests and the new ones of the last 7 days, the consent rate, and active days. Consent rate is the share of guests whose current answer is yes for email or WhatsApp (the profile consent does not count). An active day is one of the last 7 days, on the hotel's clock, with at least one guest visit.

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 contact. 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 (a test alert by email and the low score threshold) and Google review. Staff see the page read only. The manager WhatsApp contact column is not edited there: alerts go by email only. Plan, status and pilot end date are admin.hotels.update only.

Billing

Billing is manual: no online payment, and no payment card data anywhere. Everything is app admin only (admin.billing.*), on Billing (/admin/billing) and on each admin hotel page.

  • Plans. Each plan (starter, growth, pro) can be given its own name and monthly price in TND (billing_plans). No price ships with the code: until the admin sets one, an invoice needs its amount typed. A hotel's plan, status and pilot end date stay on its admin page (admin.hotels.update).
  • Invoices. One per hotel and month (invoices), with the plan name and amount copied at creation, so a later price change does not rewrite it. The amount defaults to the plan price and can be overridden, for a setup fee or a discount. They are unpaid, paid or void. Void is final: a wrong invoice is voided and a new one created, nothing is deleted.
  • Export. CSV of every invoice, or one hotel's. The list shows the latest 100, the export has all. The number is a reference, not a gapless legal sequence, and the app makes no tax document: the legal invoice is issued by the invoicing entity from this export.
  • Invoices stay when a hotel is deleted. They hold the hotel's name and the money, no guest data.
  • Every plan change, invoice, status change and export is in the audit log (billing.*).

Rooms and tables

Every room and table has its own code, a short link that leads to the capture page with src and the spot in loc, so a capture is stored with its spot. Rooms and tables are saved per hotel (hotel.spots.add, table capture_spots) from Add rooms or tables on QR codes. The field takes names, lists and number ranges (101-120, 1-12, a reversed 120-101 reads the same), at most 100 at a time and 500 per hotel. Every role, staff included, can add and remove spots. Removing (in Pick) asks first and only takes them off the list: a printed code keeps working.

Every printed code has the hotel logo in its middle (the first letter of the hotel's name without a logo) and, next to it, a tiny label for staff: 383 for a room, T4 for table 4. Codes are made with error correction level H so the logo does not stop them from scanning.

Every printed piece and download opens <web url>/q/<code> and shows that address under the code, for a camera that fails.

  • A code is 8 characters from 23456789BCDFGHJKMNPQRSTVWXYZ (no 0 O 1 I L, no vowels so none spells a word), and typing it in lower case works. The shorter address also makes a less dense QR.
  • short_links keeps the hotel id, src and the spot, one row per hotel, source and spot. hotel.qrCodes makes the row the first time and returns the same code ever after. A hotel can have 2000 rows (422 over that, existing codes keep working). The demo viewer account creates none: a spot without a code gets the long /h/ address.
  • The web route /q/<code> asks public.shortLink, which answers with the hotel's current slug, then redirects (302, never cached) to /h/<slug>?src=&loc=. A lang in the address is kept. An unknown code, or one of a suspended hotel, shows a "does not work" page. An unreachable api, or too many requests, shows a retry button.
  • public.shortLink is limited to 300 calls per ip per 10 minutes, so codes cannot be listed by guessing. The web app forwards the guest's ip, and a whole hotel wifi counts as one.
  • Rows are never removed on their own, so a spot taken off the list keeps its printed code. Deleting the hotel deletes them.
  • /h/<slug>?src=&loc= stays as it was, so codes printed before short links work as long as the slug does not change.
  • The web address itself is part of the printed code: moving the guest site to another domain needs the old domain to keep redirecting.

Printing QR codes

QR codes (/qr-codes, every role) is built around the paper, in three steps next to a live preview:

  1. What to print, picked from thumbnails of the real art:
PieceSourceFinal sizeOn the hotel's A4 printer
Room cardroomA6 portrait (105 x 148 mm)4 per sheet
Table tenttableA5 portrait, folded into two A6 faces2 per sheet (landscape)
Desk signdeskA5 portrait2 copies per sheet (landscape)
Stickers, smallrooms and tables45 x 52 mm20 per sheet
Stickers, largerooms and tables78.75 x 91 mm6 per sheet (2 x 3)
  1. Which spots, from the saved list: all, a range (From and To, numbers in number order, an empty end is open) or ticked ones. With no saved spot the piece prints one code without a number.
  2. Wording: the language on the paper (en, fr, ar or all three, default the hotel's guest language), the headline (empty keeps the default) and whether the welcome gift is shown. Stickers have no headline, and the gift is their one line benefit (the offer's title, else a default line).

Where it prints. Next to the preview:

  • My printer (A4): several pieces per sheet with crop marks in the margins. Cards come out a little under A6 and A5 (90 mm and 131 mm wide) so the marks and the white edge no office printer can reach fit around them.
  • Print shop: one piece per page at its final size, 3 mm of bleed and crop marks outside it. The page is the piece plus 8.5 mm on every side (125 x 165 mm for a room card).

The geometry is in components/qr/layout.ts. Cards have a band of the hotel's color that runs into the bleed. Words and codes stay inside a safe margin (at least 3 mm from the cut on stickers), and sticker edges are white. Every card and sticker shows its spot in a bordered tag or in bold (383, T4) so staff can sort a stack of them.

The preview is the print. One component (components/qr/art.tsx) draws the thumbnails, the preview pages, the printed pages and the saved images. Print or save PDF puts every page of the selection under body and opens the browser's print dialog: choose Save as PDF to download one file with all pages. No PDF library: the browser already shapes Arabic and lays out right to left with the app's fonts, and the QR stays vector. @page sets the paper size; print at 100% scale. The preview stays short enough to be seen whole above the analytics consent card.

PNG images and SVG images save the sticker art (hotel name, code with logo, benefit, "scan me", short address, staff label) of the selected spots, one file, or a zip when there are several. The logo is inside the file. Fonts are the viewing device's.

Cards carry the hotel logo, display name and two colors from hotel_settings, no Ritorno mark, and the perk the capture page shows: the active welcome offer's title and text, else the default welcome gift line. The offer is printed in the card's language, else in its default words (offer languages). All three puts the headline, the scan line and the offer's title in the hotel's language first, then the two others. It has no custom headline and no offer text (the page behind the code has it), and a title with no translation is printed once. Text on a brand color is black or white, whichever reads better, and the QR is always black on white.

The page warns before printing when there is no welcome offer, when it ends within 30 days (OFFER_SOON_DAYS), and when there is no logo. The link to fix it shows only to roles that can (staff just read the warning).

Trying it out. Open guest page and Test on my phone (a QR on screen) open /h/<slug>?src=&loc=&lang=&preview=1 for the first selected spot (hotel.testLink). That page says it is a preview, its submit button is off and it has no WhatsApp button, so no guest is created. It makes no short link, logs no scan and guest pages load no analytics.

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.

On a phone the same switcher sits at the top of the "More" sheet. One hotel is on screen at a time:

  • switching hotels (any successful set-active through the dashboard's /api proxy) also ends the app admin's "acting as" view, whose cookie would otherwise keep winning
  • hotel.mine answers activeId and role for the hotel the app admin named with x-hotel-id, so role gates match the data
  • the browser sends the hotel on screen as x-hotel-id on every call (QueryProvider hotelId), so a tab left open on the previous hotel is refused (FORBIDDEN) instead of acting on the new one. The team page names its hotel to better-auth the same way
  • changing the team needs a membership: an app admin acting as a hotel they do not belong to sees its members and pending invitations read only (admin.hotels.get) with a link to its admin page. Guest data and Import treat them as the owner, like the api

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), 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 (each named by its type, with the campaign or holiday it came from). 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.

Onboarding checklist

Home shows owners and managers (and the app admin acting for a hotel) six first steps until all are done. Nobody ticks them: overview.get derives each one from the hotel's own data on every load, so a step opens again if the data is removed.

StepDone whenLinks to
Logohotel_settings.logo_key is set/hotel#logo
Colorsa primary color is set, at creation or later/hotel#colors
Google reviewsthe review link is set/hotel#google-review
First QR codea guest signed up from a room, table or front desk code. Printing alone does not count/qr-codes
First gueststhe hotel has at least one guest, from any source/guests/new
Test emailsomeone sent a test from the emails page (the email.send-test audit entry). It counts with the log-only provider too/emails

The test message is email only until WhatsApp templates are approved. Done steps stay listed and linked, and the whole card goes away once all six are done.

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, email consent, WhatsApp consent, stay dates and stay 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, with one column per channel. Email is only granted when the email consent cell is an explicit yes (true, vrai, yes, oui, y, 1, نعم), the row has an address and the hotel ticked the confirmation that it holds that consent. WhatsApp reads its own column the same way, for numbers that can take it. It is logged like any other consent event with source csv, and the import itself is written to the audit log with counts only.

Headers are matched in English, French and Arabic, ignoring case, accents, _ and - (packages/common/src/guest-import.ts): Accepte WhatsApp, Consentement e-mail, email_consent, Accord séjour. Consent columns go by an allow list: one is matched only when the whole header is made of known consent words, channel words and harmless fillers (marketing, (oui ou non), (yes/no)). Anything else (consent alone, Email consent withdrawn, Accord e-mail (pas WhatsApp)) stays unmatched: the hotel is told and picks it by hand. Remapping a consent column unticks the confirmation.

The review step shows how many rows are new and how many merge into a guest already there (guests.importCheck, same hotel only; a number repeated in the file merges into its first row), with phones as they will be stored, formatted.

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 messages table. Sent messages with no delivery report yet are counted next to it
  • 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

The chart says under its title whether a bar is a day or a week. On a phone the axis shows the day number, with the month on the first bar and where it changes.

Audit log

Sensitive actions are written to the append-only audit_log table. The action names are listed in packages/common/src/audit.ts: writers are typed against that list, and a test fails when one of them has no en, fr or ar label in adminAudit.actions.

WhoPageSees
Owners and managersActivity log (/activity, audit.list)their hotel only: action, person, time on the hotel's clock. The invoice export (billing.export) is left out, filters included. No IP or metadata, and platform admins who are not on the team, or who were signed in as a team member (metadata.impersonatedBy), show as "Ritorno team"
App adminsAudit log (/audit-log, admin.audit.list)every entry, with target and IP, filtered by hotel too

Staff cannot read it. Both filter by action, person and dates (kept in the url) and load 100 entries at a time as you scroll, with a cursor so new entries never shift the next page. An entry belongs to a hotel when its metadata.hotelId or its target is that hotel, so account actions (profile, ban, impersonation) only show to the admin.

On this page