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

# Authentication and sessions

> Use your own Pinterest cookies with Pinto, and save, restore, and isolate sessions.

Anonymous reads work immediately. A logged-in session gets its own per-account quota and looks like an ordinary browser.

## Use your cookies

**1. Log in**

Log into pinterest.com in your own browser.

**2. Copy the Cookie header**

In DevTools, open **Network** and copy any request's `Cookie` header value.

**3. Pass it to Pinto**

```ts theme={null}
const pinto = createPinto();
await pinto.setCookies("_pinterest_sess=...; csrftoken=...; ...");

console.log(pinto.isAuthenticated()); // true
```

> [!WARNING]
>
> Treat cookies like passwords. Never commit them, never expose them to end users, and store them encrypted server-side.

## Save and restore sessions

Persist the session so credentials survive restarts with `useFileSession`. It's also a good guide for writing a Redis or Postgres store.

```ts theme={null}
import { createPinto, useFileSession } from "@traceryn/pinto";

const { state, saveSession } = await useFileSession("./.pinto-session");

const pinto = createPinto({
  session: state,
  saveSession: (s) => saveSession(s), // called after cookies change
});
```

For tests and short-lived jobs, use an in-memory session:

```ts theme={null}
import { createPinto, useMemorySession } from "@traceryn/pinto";

const { state, saveSession } = useMemorySession();
const pinto = createPinto({ session: state, saveSession });
```

## Multi-tenant clients

Every client is fully isolated. Device fingerprint, rate budget, cache namespace, cookies, and `fetch` all hang off the session object.

```ts theme={null}
function clientForUser(user) {
  return createPinto({
    session: user.pintoSession,
    saveSession: (s) => db.save(user.id, s),
  });
}
```

## Cookie import formats

`importCookies` auto-detects the format you paste.

```ts theme={null}
import { createEmptySession, importCookies } from "@traceryn/pinto";
import { readFile } from "node:fs/promises";

const session = createEmptySession();

// 1. Raw Cookie header (DevTools -> Network -> copy "Cookie" value).
//    Handles quotes, %-encoding, and ";" inside JSON values (g_state).
importCookies(session, "csrftoken=...; _pinterest_sess=...; g_state={...}");

// 2. Browser-extension JSON array: [{ name, value, domain, ... }, ...]
importCookies(session, extensionExportJson);

// 3. cookies.txt (Netscape / curl format, tab-separated).
importCookies(session, await readFile("./cookies.txt", "utf8"));
```


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