---
title: "Authentication"
sidebar:
  icon: log-in
description: "Every way to sign in to varsafe — dashboard login methods, account protection, sessions, and the CLI's browser and token sign-in."
---


<PageMeta />

People sign in to the **dashboard** in the browser, and the **CLI** signs in through that same browser, so a password never reaches a terminal. Machines use **API tokens**.

| You are | Sign in with | Lasts |
| --- | --- | --- |
| A person in the dashboard | Password, GitHub, GitLab, Google, Bitbucket, a passkey, or your company's SSO | 7 days, renewed while you use it |
| A person at a terminal | `varsafe login`, approved in the browser | Up to 180 days; ends after 90 days unused |
| A CI job, server or script | An [API token](/reference/api-tokens) in the environment | The lifetime chosen at creation |
| An AI agent | An OAuth grant over [MCP](/guides/mcp), or an API token | 90 days without use, or the token's lifetime |

## Unusual-access protection

Detection and security notifications are on for every account. A random HttpOnly cookie identifies a browser; varsafe does not use a hardware fingerprint. Browser updates and IP changes on a verified device normally do not interrupt access, including VPN and mobile-network changes.

A new device receives an email alert. Verification is required when that device also uses an unfamiliar network or country, when recent failed verification attempts corroborate the risk, or when an existing session loses its device binding or changes browser family. **Profile → Access protection** offers stricter verification for every unfamiliar device, including on familiar networks.

A session requiring verification cannot read, reveal, compare, export or change secrets, rotate credentials, approve CLI or agent access, or change security settings. These checks run on the server for API requests too. Submit a fresh authenticator code or choose **Continue with passkey** to verify directly on the page, even if you originally signed in with GitHub. Cancelling the passkey prompt keeps your session available for a retry. Accounts without a registered passkey or enabled MFA can request a code at their verified email address; paste it into the original browser within ten minutes. Email verification does not replace an account's existing MFA.

Alerts contain the IP, UTC time, browser information and approximate location when available. **This wasn't me** opens a confirmation page, then revokes the affected session immediately. The link expires after 24 hours and can be used once. Opening the email or previewing the link does not revoke anything. After reporting access, reset your password, review other sessions and connected apps, rotate potentially exposed credentials, and enable MFA.

Existing browser sessions are checked too; the first request after this protection is deployed may require verification. Lost device cookies have the same effect. You can still sign out, verify your email, obtain a challenge, or sign in with a passkey/authenticator to recover.

### What you see

- **Access protection** (`/app/access-security`) shows the always-on checks and alerts, the optional **Always verify new devices** switch, and this session's device, IP and approximate location. Signed-out visitors sign in and return here; a connection failure offers a retry.
- **Confirm it’s you** (`/app/access-security/verify`) opens as a dedicated page when an action is blocked. It explains that access is temporarily restricted and returns you to your original page after verification. It cannot be dismissed into a page with missing data; sign-in and recovery remain available. Only methods registered for the account are offered. Passkeys use the existing sign-in flow; authenticator users can switch to a saved recovery code. Email-only accounts choose **Send verification code**, then paste the full code from the branded email into the original browser. New codes use the same 10-character, 50-bit format as CLI approval codes, displayed as `7K9MD-2WX3R`. Code fields share a segmented design across email, authenticator, recovery and CLI screens. Spaces, the separator and lowercase email/CLI input are accepted; recovery codes retain their original case. Complete email and authenticator codes verify automatically after a short pause, with loading dots; Enter and the button remain available. A failed request does not retry automatically. CLI approval still requires explicit consent. Resend shows a 60-second countdown; server-side hourly limits still apply.
- **Session verified** confirms a successful proof. Choose **Continue**, then retry the interrupted action. Writes are never automatically repeated.
- **Don’t recognize this activity?** is reached from **This wasn't me** in the alert email. Opening it changes nothing. **Revoke this session** explicitly signs out the affected session, then offers password reset, session review and advice to rotate exposed credentials. Expired, reused or missing links offer account review and password recovery. Password recovery works while you remain signed in on a legitimate device.

### Code formats and safeguards

| Purpose | Format | Main safeguards |
| --- | --- | --- |
| Email sign-in and session verification | 10 random Base32 characters, in two groups of five (50 bits) | Ten-minute expiry, single-use proof, three guesses per challenge, keyed hashes; bound to the original challenge/session |
| CLI approval | The same 10-character Base32 format | Ten-minute expiry, authenticated and origin-checked approval, explicit consent, throttled lookups, one exchange; separate 384-bit device/grant secrets |
| Authenticator app | Standard six-digit TOTP, 30-second period | Existing Better Auth verification and account lockout; authenticated step-up also uses the account attempt budget |
| Authenticator recovery | Ten mixed-case letters/digits, displayed in two groups | Existing encrypted storage and single-use consumption; authenticated checks share the account attempt budget |
| MCP OAuth | Long machine-generated authorization codes, access and refresh tokens | PKCE, exact redirect/resource validation, explicit scope consent, single-use authorization-code exchange and replay handling |
| Password reset, email confirmation and suspicious-access report links | Long link tokens | Purpose-specific expiry and verification; report links expire after 24 hours and require explicit confirmation |

Email-code verification and existing-session authenticator/recovery-code checks share a database-backed budget of ten attempts per account per 15-minute window, across devices, sessions and IPs. Code resends and new challenges do not replenish that budget. Normal two-factor sign-in retains Better Auth's account lockout at ten failures for 15 minutes. Email delivery is limited to one code per account per minute and five per hour across the email sign-in and session-verification flows. Rate-limit screens distinguish email delivery from code verification, show the server’s remaining wait, and keep recovery actions available. Changing code methods or reopening the verification page does not reset the countdown. An email delivery limit still lets you enter a code already received; an exhausted challenge requires signing in again. Failed requests still consume their rate-limit slot; they cannot roll back the guessing budget. After a temporary limit, wait for its window to expire or sign in with a passkey; password recovery remains available.

Email codes are HMAC-SHA-256 protected using the authentication secret and a challenge-specific salt. Codes mailed by an earlier deployment retain their original verification format and expiry. Deploy migration `173_email_code_protection.sql` before switching the API, and drain older API instances before issuing the new format. Rotating the authentication secret invalidates outstanding new email codes; request another after the cooldown. An email code proves access to the mailbox and is not phishing-resistant MFA. Existing passkey/MFA requirements cannot be downgraded to an email code.

## Dashboard login methods

| Method | Notes |
| --- | --- |
| **Email and password** | Add [two-factor authentication](#two-factor-authentication-2fa) for a second factor |
| **GitHub, GitLab, Google, Bitbucket** | Click the provider's button on the sign-in page |
| **Passkey** | **Sign in with passkey**, or pick the passkey your browser offers in the email field |
| **SSO** | SAML 2.0 or OIDC through your company's identity provider, on the Team plan. See [Single sign-on](/guides/sso) |

**SSO is detected from your email.** Type your work email on the sign-in page: if your company has set up SSO for that domain, the page offers **Continue with SSO**. **Use password instead** remains available.

### OAuth login

Click a provider button, approve varsafe at the provider, and you are signed in.

If an account with the same email already exists under another method, the provider sign-in is refused rather than silently attached to that account, which stops anyone from taking over an account through a provider that vouches for an email they do not own. The sign-in page says **There is already a varsafe account with this email**: sign in the way you did before, then [connect the provider](#connected-accounts) from your profile.

### Connected accounts

**Connected accounts** on your **Profile** lists GitHub, GitLab, Google and Bitbucket, and which of them are connected.

- **Connect** sends you to the provider to approve, then back to your profile. The provider account must use the same email address as your varsafe account, and the provider must have confirmed it. Your own email must be confirmed first.
- **Disconnect** stops that provider signing you in. It is refused when your account has no password and no other provider, and it needs a session signed in within the last day.

A provider account already connected to another varsafe account cannot be connected to yours.

Connecting or disconnecting a provider here is recorded in your [audit log](/reference/operations#event-catalog) as `auth.provider_connected` or `auth.provider_disconnected`, naming the provider, and is not kept if the record cannot be written.

### Confirming your email

A new account can be used straight away. varsafe sends a confirmation link, valid for 24 hours. You need to have confirmed your email before you:

- invite someone or accept an invite
- create a team
- transfer ownership
- configure SSO
- connect an AI agent
- connect a sign-in provider

---

## Passkeys

Passkeys sign you in with Touch ID, Face ID, Windows Hello or a hardware key such as a YubiKey, with no password to phish or reuse. Each passkey is bound to the varsafe domain.

### Adding a passkey

1. Open your **Profile** in the dashboard
2. In the **Passkeys** card, click **Add passkey**
3. Optionally name it ("MacBook Touch ID", "YubiKey 5")
4. Follow your browser's prompt

Register more than one, on different devices, so losing one device does not lock you out. Passkeys can be renamed or deleted from the same card.

### Passkey-only mode

Passkey-only mode refuses every sign-in that is not a passkey: password, GitHub, GitLab, Google, Bitbucket and SSO. A refused sign-in says **This account is in passkey-only mode. Sign in with one of its passkeys.**

- **Requirements:** at least **2 passkeys** and a password on the account. The **Passkey-only mode** control appears in the Passkeys card once both are in place.
- **Enabling it revokes every session**, including the current one. Sign back in with a passkey.
- **While it is on**, a session signed in with a passkey can still change the password and turn two-factor authentication on or off.
- **Disabling it** takes your password.

:::warning
Keep at least two working passkeys while the mode is on. The control disappears if you drop below two, so delete a passkey only after adding its replacement.
:::

---

## Two-factor authentication (2FA)

Two-factor authentication adds a time-based one-time code (TOTP) to password sign-in. It is available on accounts that have a password.

### Enable 2FA

1. **Start setup**

    Open your **Profile** and start two-factor setup.

2. **Enter your password**

3. **Add varsafe to your authenticator**

    Scan the QR code with an authenticator app (1Password, Google Authenticator, Authy and the like), or type the secret shown under it.

4. **Confirm a code**

    Enter the 6-digit code from the app.

5. **Save the backup codes**

    **Save the 10 backup codes**, then confirm with **I've saved the codes**. Keep them in a password manager or another safe place, not on the device that holds the authenticator.

### Using 2FA

| When | Do |
| --- | --- |
| Signing in | After your email and password, enter the current 6-digit code. Codes change every 30 seconds |
| You lose your authenticator | Sign in with a backup code. Each one signs you in once |
| Turning 2FA off | From your **Profile**, turn two-factor off and confirm with your password |

---

## Session management

### Viewing sessions

The **Active Sessions** card on your **Profile** lists every browser signed in to your account, with its device and browser, IP address and last activity. **Current** marks the one you are using.

### Revoking sessions

- The revoke button on a row (**Revoke session**) signs that browser out
- **Revoke all other sessions** keeps only the current one

A revoked session stops working on its next request.

### Session properties

- **Lifetime:** a session ends 7 days after it was last extended. Using it extends it, at most once an hour, so an active session stays signed in and an idle one ends within a week.
- **Renewal:** changing the password with **Sign out all other devices**, or turning two-factor authentication on or off, replaces the session you are using with a new one. The audit log records it as `auth.session_renewed`, with the reason and the session it replaced, not as a sign-in.
- **Concurrent sessions:** the plan sets a threshold of 5 per person on Developer (200 on Team). It is a prompt, not a ceiling: past it the dashboard shows **Session limit reached** after sign-in and offers to revoke old sessions, but you can continue and a new session is still created.

CLI logins are listed separately, in the **CLI Sessions** card on your Profile.

---

## Password change and reset

**Changing** your password, from your Profile, keeps your other sessions signed in unless you tick **Sign out all other devices**. Tick it if you are changing the password because you think someone else knows it. Each change is recorded in your audit log as `auth.password_changed`, saying whether the other devices were signed out; a reset is recorded as `auth.password_reset`.

**Resetting** a forgotten password:

1. Click **Forgot password?** on the sign-in page
2. Enter your email address
3. Open the link in the email within 1 hour and choose a new password

:::info
A reset signs the account out everywhere. It revokes every browser session, every CLI login, every agent connection's refresh token, and every API token the account created. Pipelines using those tokens need new ones.
:::

---

## CLI authentication

The CLI has two ways in: a browser login for people and an API token for machines. There is no email and password login in the terminal.

### Browser login (default)

```bash
varsafe login
```

1. The CLI shows a confirmation code such as `7KQ2M-X9D4F` and opens the dashboard approval page (it prints the URL if no browser opens)
2. In the browser, sign in if needed, check that the code matches the one in your terminal, and approve
3. The CLI picks up the approval at once, over a live connection that falls back to polling every few seconds

The code expires after **10 minutes**. `varsafe login --force` signs in again when a login already exists.

A CLI login is its own credential, not a copy of your browser session. It lasts at most **180 days** from approval and ends sooner if the machine goes **90 days** without using it. Revoke one any time from the **CLI Sessions** card on your Profile. Removing you from a team revokes your CLI login for that team.

:::info
Browser login stores its credential encrypted, with the key in the operating system keychain (see [Credential storage](#credential-storage)). On a machine with no keychain, a login run at a terminal offers a **machine token** instead. A CI runner has nobody to approve a login: use an API token there.
:::

### API token

For CI/CD and automation, use an [API token](/reference/api-tokens). Pick the input that keeps the value out of shell history:

| Where you run | How the token gets in | Stored on the machine |
| --- | --- | --- |
| **CI/CD** | The [`VARSAFE_API_TOKEN` environment variable](#environment-variable-recommended-for-cicd), from your CI secret store | No. There is no `login` step |
| **Workstation** | `varsafe login` with a [masked prompt](#secure-prompt-recommended-at-a-workstation), [standard input](#stdin-pipe) or [`VARSAFE_TOKEN`](#from-varsafe_token) | Yes, as the login |

:::warning
Storing a token with `varsafe login` needs the operating system keychain, so it fails on a CI runner, which has none. In CI, set the environment variable and skip `login`.
:::

#### Environment variable (recommended for CI/CD)

No `login` step at all. Set `VARSAFE_API_TOKEN` (or `VARSAFE_TOKEN`, read when the first is not set) from your CI secret store:

```bash
export VARSAFE_API_TOKEN=vs_at_vsafe_example
varsafe run -- npm run build
```

The variable is used when the machine has no stored login. If `varsafe login` has stored a credential, that credential takes precedence and the variable is ignored; `varsafe whoami` shows which one a command will use. See the [CI/CD guide](/guides/ci).

#### Secure prompt (recommended at a workstation)

```bash
varsafe login -T
# or
varsafe login --token-prompt
```

Masked input; nothing lands in shell history.

#### Stdin pipe

```bash
secret-manager read varsafe-token | varsafe login -t -
# or from a file in RAM
varsafe login -t - < /dev/shm/token.txt
```

`-` tells the CLI to read the token from standard input.

#### From `VARSAFE_TOKEN`

```bash
VARSAFE_TOKEN=vs_at_vsafe_example varsafe login
```

A bare `varsafe login` with `VARSAFE_TOKEN` set stores that token as the login.

#### Why there is no `--token <value>` flag

{/* illustrative — this command intentionally fails */}
```bash
# Rejected, by design
varsafe login --token "$VARSAFE_API_TOKEN"
```

An inline value is visible in shell history and to any process that can read `ps` output, so the CLI refuses it and points to the options above. `--token` with no value means "prompt me"; `--token -` means "read stdin".

### Credential storage

The CLI keeps its credential in `~/.varsafe/varsafe.db`. Which credential it is decides how it is stored, how long it lasts and what [signing out](#signing-out) does:

| | Browser login | Machine token | API token (`login -T`) |
| --- | --- | --- | --- |
| **Stored** | Encrypted with AES-256-GCM, with the key in the operating system keychain | Unencrypted, in the same file, inside `~/.varsafe`, a directory only your user can read | Encrypted with AES-256-GCM, with the key in the operating system keychain |
| **Lasts** | At most 180 days from approval, and ends sooner after 90 days unused | At most 30 days | The lifetime chosen at creation |
| **Signing out** | Revokes it on the server, then clears it from the machine | Revokes it | Clears it from the machine only |

The encryption key is kept in the operating system keychain (macOS Keychain, or the Secret Service on Linux), so a copy of the file alone does not reveal the credential. `varsafe doctor` checks that the keychain works on this machine.

The **machine token** is what a browser login falls back to on a machine with no keychain: there is no keychain to hold a key, so it is stored unencrypted. To limit what a copied file is worth, it is restricted to one team and the projects and environments you approved.

### Signing out

```bash
varsafe logout
```

For an API token stored with `varsafe login -T`, `logout` clears the token from the machine only: revoke the token itself in the dashboard if the machine is no longer trusted.

---

## Deleting your account

Open your **Profile**, go to **Danger Zone**, and type `delete my account` to confirm. Deletion is permanent.

You are signed out everywhere at once, and you leave every team. The account itself is erased a few seconds later. Until then, signing in with it is refused, and its address cannot be used for a new account. Encrypted backups keep a copy for a few weeks, until they expire.

The invitations you sent that have not been accepted are revoked at once, in every team you belong to. Once the account is erased, no invitation shows your address: a team's list says it was sent by a deleted account.

## What sign-in does not do yet

- **No hardware-based device attestation.** Device recognition depends on a browser cookie, not physical hardware. Turn on two-factor authentication or use passkeys for stronger proof.
- **SSO is not enforced.** Setting up SSO for a domain does not stop its users from signing in with a password or a provider.
- **No provider account under another email.** A provider can be connected only with the same email address as your varsafe account.
