> ## Documentation Index
> Fetch the complete documentation index at: https://polar.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# polar auth

> Manage your Polar sessions and active organization

```bash theme={null}
polar auth <subcommand> [flags]
```

**Environment variables**

| Variable | Description |
| - | - |
| `POLAR_ACCESS_TOKEN` | Use this token instead of polar auth login: an organization access token, or an OAuth or agent access token |
| `POLAR_ENVIRONMENT` | Environment of POLAR\_ACCESS\_TOKEN: sandbox or production. Defaults to production |

**Subcommands**

* [`polar auth login`](#polar-auth-login) Sign in to Polar through your browser
* [`polar auth whoami`](#polar-auth-whoami) Show the active organization
* [`polar auth list`](#polar-auth-list) List the organizations you have access to
* [`polar auth org`](#polar-auth-org) Choose the active organization
* [`polar auth token`](#polar-auth-token) Give your app its own organization access token: a human approves it in the browser, with any --scope preselected, and the CLI prints it
* [`polar auth logout`](#polar-auth-logout) Sign out and remove saved sessions

## polar auth login

Sign in to Polar through your browser

```bash theme={null}
polar auth login [flags]
```

**Flags**

| Flag | Type | Description |
| - | - | - |
| `--sandbox` | `boolean` | Use the sandbox environment |
| `--production` | `boolean` | Use the production environment |
| `--new-session` | `boolean` | Sign in again even if a session is already saved |

**Examples**

Choose sandbox or production, then sign in

```bash theme={null}
polar auth login
```

Sign in to sandbox

```bash theme={null}
polar auth login --sandbox
```

Sign in to production again, replacing the saved session

```bash theme={null}
polar auth login --production --new-session
```

Without a browser, e.g. in CI or as an agent, skip login and use an access token

```bash theme={null}
export POLAR_ACCESS_TOKEN=<token> POLAR_ENVIRONMENT=sandbox
```

## polar auth whoami

Show the active organization

```bash theme={null}
polar auth whoami [flags]
```

## polar auth list

List the organizations you have access to

```bash theme={null}
polar auth list [flags]
```

## polar auth org

Choose the active organization

```bash theme={null}
polar auth org [flags] [<organization>]
```

**Arguments**

| Argument | Type | Description |
| - | - | - |
| `organization` | `string` | Organization ID or slug. Omit to pick from a list (optional) |

**Examples**

Pick the active organization from a list

```bash theme={null}
polar auth org
```

Set it by slug or ID, for scripts and agents

```bash theme={null}
polar auth org acme
```

## polar auth token

Give your app its own organization access token: a human approves it in the browser, with any --scope preselected, and the CLI prints it

```bash theme={null}
polar auth token [flags]
```

**Flags**

| Flag | Type | Description |
| - | - | - |
| `--scope` | `string` | Scope to preselect on the token page, e.g. products:read. Repeatable |
| `--org` | `string` | Organization ID or slug for this invocation only |

**Examples**

Add a token for the active organization to .env.local

```bash theme={null}
echo "POLAR_ACCESS_TOKEN=$(polar auth token)" >> .env.local
```

Preselect scopes and store the token as a GitHub Actions secret without writing it to disk

```bash theme={null}
polar auth token --scope products:read --scope checkouts:write | gh secret set POLAR_ACCESS_TOKEN
```

As an agent without a saved session, use your own access token; a human still approves the app token

```bash theme={null}
POLAR_ACCESS_TOKEN=<your access token> polar auth token --org <org id> --scope events:write
```

Create a token for a specific organization

```bash theme={null}
polar auth token --org acme --scope events:write
```

## polar auth logout

Sign out and remove saved sessions

```bash theme={null}
polar auth logout [flags]
```

**Flags**

| Flag | Type | Description |
| - | - | - |
| `--sandbox` | `boolean` | Use the sandbox environment |
| `--production` | `boolean` | Use the production environment |
| `--all` | `boolean` | Remove every saved session |

**Examples**

Sign out, asking which session only if you have both

```bash theme={null}
polar auth logout
```

Remove every saved session

```bash theme={null}
polar auth logout --all
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.