---
title: "Hotels"
description: "How a hotel is modeled, who can do what, and where branding lives."
url: https://docs-staging-lehoetel.findmalek.engineer/docs/hotels
markdown: https://docs-staging-lehoetel.findmalek.engineer/docs/hotels.md
---

# Hotels

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, including deleting 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.

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` (the **Hotel** page in the dashboard, with a contrast warning on the colors) and the logo with `hotel.logo.*`. 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"] })`.

## 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`, `page`), so a search can be shared. `consent=none` means no email and no WhatsApp consent. On phones each guest is a card, from `md` up it is a table.

## 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`). 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/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.
