# Sign in at either site

> Serve a realm from two sites with a host name at each, so a user signs in once and stays signed in wherever they land.

Your realm is served from a site in each of two regions, and you want users to reach the nearer one, or the
other if one is lost. With a host name at each site, a user signs in once: whichever site their browser or app
reaches next, they are signed in, and signing out at either site ends the session at both.

**Before you start:** you administer the realm's parent (creating a realm and changing its host names are done from
the parent), you know the host name you want at each site, and your session is in `$CVYUH_SESSION`
([Call the API](/develop/api/)). It's done through the API. Which sites serve your realm is agreed with
Cvyūh: see [Multi-site realms](/platform/sites/multi-site-realms/).

## Set it up

<Steps>

1. **Give the realm a host name at each site.** Here the realm is `engineering`, beneath yours, with one host name
   for the site in Europe and one for the site in the US. Send the realm's
   whole list:

   ```sh
   curl -X PATCH https://foobar.cvyuh.com/api/v0/am/global/realms/v1/<realm id> \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "hostnames": ["foobar-engineering-eu.cvyuh.com", "foobar-engineering-us.cvyuh.com"] }'
   ```

   The realm answers `200`, naming the host names it `claimed` and `freed`. The realm's `id` is in the realms list,
   `GET https://foobar.cvyuh.com/api/v0/am/global/realms/v1`. A new realm takes the same `hostnames` when you create
   it: see [Realms and sub-realms](/platform/realms/sub-realms/#set-it-up).

2. **Decide what apps see as the issuer.** By default each host name is its own issuer, so an app that signed in at
   `foobar-engineering-eu.cvyuh.com` must refresh there too. If apps should see one issuer whichever site they reach,
   set a [base URL](/platform/realms/realm-base-url/).

</Steps>

Nothing else to set: the realm, its apps, users and sessions are the same at every site.

## Check it worked

Sign in at one host name, then open the other in the same browser a few seconds later: you are signed in. Sign out at
the second, and the first asks you to sign in again once the sign-out has reached it. Introspection of the same token
at either site gives the same answer.

<Aside type="note" title="How long things take">
  Changes travel between sites in the background, usually within seconds. Until a new session's copy arrives, the
  other site asks the user to sign in; until a sign-out's copy arrives, the other site still honors the session. A
  sign-in in progress finishes at the site where it started.
</Aside>

## If it fails

- **`400`, "a realm holds at most 3 hostnames".** Free a name you no longer need, or ask Cvyūh to raise the limit.
- **`409`.** Another realm holds the name. Choose another.
- **An app's refresh fails at the second site.** Each host name is its own issuer: set a
  [base URL](/platform/realms/realm-base-url/).

The change to the realm's host names is recorded on its audit trail: see
[Host names](/platform/realms/hostnames/#audit-record).

## Undo it

Send the realm's host names again without the one you no longer want. The host name is freed, and users reach the
realm only at the others.

## Related

- [Multi-site realms](/platform/sites/multi-site-realms/): what every site shares and what stays local.
- [Host names](/platform/realms/hostnames/): the limits on a realm's host names.
- [Logout](/workforce-identity/applications/single-sign-on/logout/), [Refresh tokens](/workforce-identity/applications/single-sign-on/refresh-tokens/),
  [Introspection](/workforce-identity/applications/revoke-access/introspection/): what apps see across sites.
