Authentication, authorization & accounting

Every custom app runs on OpenThink accounts, so you don't build a login screen, store passwords or write permission checks yourself. OpenThink handles the three A's:

| | Question | In OpenThink |

|---|---|---|

| **Authentication** | Who is this? | OpenThink sign-in, `think.viewer` |

| **Authorization** | What may they do? | Roles, `think.capabilities`, row-level permissions, sealed tables |

| **Accounting** | Who did what? | `_by` / `_by_name` on rows, "Created by", version history |

Authentication — who is viewing

`think.viewer` is `{ id, name, email, image }` or `null`. `id` is the person's OpenThink account id and never changes — use it, not the email, to tell people apart.

```js

if (think.viewer) {

hello.textContent = `Hi, ${think.viewer.name}`;

} else if (!think.signedIn) {

loginButton.hidden = false;

loginButton.onclick = () => think.signIn(); // back to this page after sign-in

} else {

askButton.onclick = () => think.requestViewer().then(draw);

}

addEventListener("think:viewer", draw);

```

- The viewer is known for the owner, for people invited by email, and for people who agreed to tell the page who they are.

- For a public link, turn on **Ask viewers for their name and picture** in the Share dialog — or call `think.requestViewer()` from a button. Viewers can take the permission back from the page menu.

- Your app must still work when `think.viewer` is `null` (signed-out or uninvited visitors).

- Call `signIn()` and `requestViewer()` only from a button click, in the same tab.

Authorization — what they may do

**Page roles.** Who can open the app and edit its code follows normal [sharing](https://openthink.app/n/26c72c31ab9c): View, Comment or Edit, by invitation or by link. Hide editing tools from people who can't edit:

```js

const canEdit = think.capabilities.canEdit; // false for View, Comment, link visitors

document.documentElement.classList.toggle("read-only", !canEdit);

```

`think.role` is `"owner"`, `"edit"`, `"comment"` or `"view"`. The real check always happens on OpenThink's server — hiding a button is only for a cleaner screen.

**Row-level permissions.** Let people write to a table without Edit access to it:

| Rule | Lets a person |

|---|---|

| Read all, edit own | See every row; add rows; edit and delete only rows they created |

| Own | Add rows; see, edit and delete only rows they created |

| Append | Only add rows; see none |

OpenThink filters the rows for you — a query returns only what the rule allows, with no `WHERE` clause needed. Writing requires sign-in.

**Sealed tables.** Anyone who can open an app can read the tables its code refers to. If a table holds answers, scores or private data, seal it: only people with access to the table itself can read it. Tables with row-level permissions are sealed automatically.

Accounting — who did what

- **Row authors.** With row-level permissions, every row gets read-only `_by` (the creator's account id) and `_by_name` columns, and owners and editors see a **Created by** field on each row.

- **Version history.** Edits to the app's code — on the web or from an AI assistant — are saved in version history, so you can see and restore earlier versions. See [Versions & publishing](https://openthink.app/n/615848fbc70f).

- **Rate limits.** Each person can add up to 60 rows a minute, which keeps a buggy or abusive client from flooding a table.

Checklist before you share

- The app works when `think.viewer` is `null`.

- Tables with private data are sealed, or use row-level permissions.

- No secrets in the code — anyone who can open the app can read all of it.

- User input reaches SQL only as parameters.

Next

- [Connect your database](https://openthink.app/n/03134f0f5a9f)

- [Live collaboration](https://openthink.app/n/5b39c176b328)

- Guide: [Collect answers from students (or anyone)](https://openthink.app/n/718fb1aba5cb)