# Accounts and admin

How the first account on an Orbik install is made, how other people get one, and how the install's
admins answer access requests and reset forgotten passwords.

## The first account

A new install has no accounts. While it has none, the API prints a one-time **setup code** in its
log, and a link to the setup page with the code in it (`/setup?key=…`); in the Docker install,
`docker compose logs api` shows both. Open the link and the code is filled in (open the web app
without it and it asks for the code): add your email and a password of at least eight characters,
and choose **Create account**. The code works once. After that the install is claimed: the setup
link sends you to the sign-in page, and the API's log says so under the link.

You can also make an account from a terminal. It asks for the password there:

```sh
# Docker install
docker compose exec api node src/cli/seedUser.js --email you@example.com

# Without Docker
pnpm --dir backend run seed:user -- --email you@example.com
```

Either way, once one account exists the setup code is gone.

An install whose first account is made another way, with `seed:user` for instance, can turn setup
off with `ORBIK_FIRST_RUN_SETUP=off`: the API prints no code, the sign-in page stays the sign-in
page and `/setup` leads to it.

## How other people join

**By invite.** The usual way in: someone who manages a workspace sends an invite link, and opening
it creates the account if the address has none (see
[Workspaces and members](https://orbik.io/docs/guides/workspaces-and-members.md#inviting-someone)).

**By asking.** The **Request access** form at `/signup` takes an email address and puts it under
Settings → Admin for an admin to approve. The form answers the same whoever asks, so it never tells
anyone whether an address already has an account. Approving it gives the person a one-time link
that makes their account.

Orbik has no self-service signup: nobody gets an account without an invite, an admin's approval or
someone with access to the server. An install upgraded from a release that had it, and still
setting `ORBIK_SIGNUP=open` or `ORBIK_SIGNUP_VERIFY_EMAIL=true`, does not start until the setting is
removed, so that it is not left believing anyone can sign up.

Settings like these are listed in [Configuration](https://orbik.io/docs/self-hosting/configuration.md).

## Signing in with Google

With `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` set, the sign-in page offers **Continue with
Google**.

- **An address that already has an account** signs in to it, whichever way the account was made,
  as long as Google says it has verified the address. That links the Google account: from then
  on the account is found by it. The password, if the account has one, keeps working.
- **An address with no account** does not get one: the sign-in page says there is no account, and
  the person asks for an invite or for access. Once they have an account, by either, Google signs
  them in to it.
- An account linked to one Google account does not sign in with another that has the same address
  (an address moved between Google accounts). Sign in with the password, or with the first one.

To set it up, make an OAuth client in [Google Cloud's console](https://console.cloud.google.com/apis/credentials):

1. On the **OAuth consent screen**, choose *External*, name the app and add the `openid` and
   `email` scopes. Nothing else is asked for.
2. Under **Credentials**, create an **OAuth client ID** of the type *Web application*, with this
   authorised redirect URI: your install's address followed by `/v1/auth/google/callback`, such as
   `https://orbik.example.com/v1/auth/google/callback` (`ORBIK_URL`, or `PUBLIC_API_URL` without
   Docker, where the API's own address is the one that counts).
3. Put the client's ID and secret in `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` and start the
   install again.

## The Admin page

The install's admins are the addresses in `ORBIK_ADMIN_EMAILS` (comma-separated), or, with it
unset, the install's first account. They find **Admin** under **Settings**, in any workspace,
below the workspace's own sections (`/admin` leads there too, and is where an admin with no
workspace yet finds it); for anyone else it does not exist. Being an install admin is separate from a workspace role: it gives
no access to anyone's workspaces.

**Access requests** are listed with where each stands: **Waiting**, **Approved**, **Joined** or
**Dismissed**.

- **Approve** makes a one-time link for that address to create their account. It works for seven
  days. If the install sends email, the link is emailed to them; it is also shown to you once, to
  copy and send yourself. **New link** replaces the link of an approved request that was lost.
- **Dismiss** turns a request down.

When the install sends email, admins are also told about each new request.

**Password reset link** makes a reset link for someone who can't get one by email: enter their
email and choose **Make link**, then send it to them.

### No install admin

A deployment that is administered some other way can have no install admin at all, with
`ORBIK_INSTALL_ADMIN=off`. Then no account is an admin, whichever was first: there is no Admin page,
and nobody can ask for access, since nobody would answer. `/signup` tells a person to ask for an
invite, and the sign-in page says the same. A forgotten password is reset by email, so the install
must send email (`SMTP_URL`); the API does not start without it, or with `ORBIK_ADMIN_EMAILS` also
set. The terminal's `reset:password` keeps working.

## Changing your password

**Settings → Account**, in any workspace, changes your password (`/account/password` leads there
too, and is where an account with no workspace yet changes it): enter the current password and the
new one twice. The new password works at once, this browser stays signed in, and the account is
signed out everywhere else. An account made with **Continue with Google** has no password, and
the section says so; **Forgot password?** gives it one.

## Forgotten passwords

**Forgot password?** on the sign-in page works when the install sends email (`SMTP_URL` and
`EMAIL_FROM`): enter the account's email, choose **Send reset link**, and a link arrives that works
once, for an hour.

An install that sends no email says so on that page and asks the person to get a link from the
admin, who makes one under **Settings → Admin** or from a terminal:

```sh
# Docker install
docker compose exec api node src/cli/resetPassword.js --email user@example.com

# Without Docker
pnpm --dir backend run reset:password -- --email user@example.com
```

Either way the link works once, for an hour, and replaces any earlier link for that account.
Opening it lets the person choose a new password; it signs them in in that browser and signs the
account out everywhere else.
