# Login and sessions

Follow the form-first input rules in the [main entry](../SKILL.md). Use the same confirmed CLI and execution environment for authentication and subsequent Seller commands.

## Install and configure the CLI

If the CLI is missing or does not support a command you need, check for Node.js >=22 and install the CLI for the target environment.

```bash
node --version
npm install -g openany-cli@latest --registry=https://registry.npmjs.org/
```

To install and check the Dev CLI:

```bash
npm install -g openany-cli-dev@latest
openany-dev --help
```

Confirm that the Backend shown in help matches the target environment. In Dev, replace `openany` with `openany-dev` in this guide and the other references. If a command or flag is unrecognized, check its help and report the limitation if it remains unsupported. Do not substitute preloading, request rewriting, or CSRF probing for a supported CLI entry point.

## Check for an existing session

If the user is known to be signed out, skip `seller status` and go straight to email login. Reuse a valid session. Run `openany seller status -j` once only if session status is unknown and you need to check it. Reuse existing Seller query results. If it returns `local.configured: false` or lists `email_session` as missing, start email login. A missing `application` does not require a new login. If only local configuration is available and `remote` is null, follow the main entry to confirm the remote access needed for this task.

## Complete email login

If the email address is missing, use a native text-input form to ask only for that address and wait for the user's reply. Once the target CLI, email address, and login authorization are confirmed, the agent runs:

```bash
openany auth email send --email EMAIL_ADDRESS -j
```

Use an authorized mailbox tool to read the code for this attempt. Otherwise, use the native text-input form to ask only “The verification code has been sent. Please enter the 6-digit code you received for this attempt.” Preserve leading zeros. Do not echo the code or resend it. Reuse the successful verification receipt before continuing with the Seller task.

```bash
openany auth email verify --code SIX_DIGITS -j
```

## Session expiration and recovery

If the email session returns 401, run:

```bash
openany auth email refresh -j
```

If the refresh is denied, complete a new authorized email login. If the CLI returns a recovery file, use only the confirmed path it returned:

```bash
openany auth recover --file RETURNED_PATH -j
```

If the refresh result is uncertain, recover the session or sign in again before continuing writes. Do not print the recovery file, overwrite credentials manually, or switch to an API key. Recheck the account and supplier after recovery. If the identity differs, ask the user before switching.

Production stores login state in `~/.config/openany/credentials.json` or in the directory set by `OPENANY_CONFIG_DIR`. Dev uses `~/.config/openany-dev/credentials.json` or the directory set by `OPENANY_DEV_CONFIG_DIR`. Directory permissions are 0700 and file permissions are 0600. Do not ask users to print or edit the file. After login, return to the main entry to confirm account and supplier permissions.
