# ctx.user

Who is here. Whether someone is signed in, at once, and — for apps that keep data — an id for this person that is yours alone, and whether this page can use their account without asking.

## Calls

`ctx.user`

```ts
ctx.user.signedIn      // true when someone is signed in to Fave1 — known at once (in app mode, only for apps that ask the account)
ctx.user.id            // this person's id as your app sees it, or undefined
ctx.user.granted       // true when storage and pub work here without asking
ctx.user.plus          // 'plus' · 'free' — Fave1 Plus, for extras you keep for Plus
ctx.user.tier          // 'free' · 'basic' · 'plus' · 'ultra' — their plan by name, or null
await ctx.user.load()  // waits for the first answer, then gives you the same object — the id only where granted
```

## An id that is different in every app

Fave1 owns sign-in; your app never sees an email or an account number. What it gets is an opaque id — 24 characters, stable for this person in *this* app, and different in every other app, so nobody can line people up across apps. It is the same value as the `id` on rows that come back from [ctx.pub](https://developers.fave1.com/docs/ctx-pub.md), on every peer in a [ctx.live](https://developers.fave1.com/docs/ctx-live.md) room and on `by` of a room change — which is how you know a row, a cursor or an edit is theirs.

Only apps that declare `storage` or `pub` get one — that is when the runtime asks the account. In app mode it arrives a moment after launch: `ctx.user.id` is `undefined` until then, so `await ctx.user.load()` before you need it. **On someone else’s site it stays `undefined` until that site has said yes to your app** ([granted](#granted)) — otherwise any page could tell the same visitor apart from site to site. It fills in right after the first storage or pub call goes through.

## Already allowed here?

On someone else’s site, the first [ctx.storage](https://developers.fave1.com/docs/ctx-storage.md) call — or the first [ctx.pub](https://developers.fave1.com/docs/ctx-pub.md) post, [ctx.shared](https://developers.fave1.com/docs/ctx-shared.md) write or [ctx.live](https://developers.fave1.com/docs/ctx-live.md) join — shows a one-time OK before it goes through. `granted` tells you in advance whether that will happen: `true` when this site already said yes to your app, in app mode, and in DEV builds; `false` when the first account call here will ask first, or nobody is signed in.

`src/index.ts`

```ts
// Settings follow the person from site to site — but never ask just for them
const u = await ctx.user.load();
if (ctx.can('storage') && u.granted) applySettings(await ctx.storage.get('settings'));
// not granted yet: open with this browser's settings, and sync after the person saves something
```

Use it to decide what to read *at launch* — your settings, last session, a badge count — without putting a prompt in front of someone who only opened your app to look. Anything the person asked for (a save, a post) should just call the API: the OK appears, they tap it, and `granted` turns `true` for the rest of the session.

It is `undefined` until the runtime has asked the account, and for apps that declare neither `storage` nor `pub`. It says only whether the OK will appear — `ctx.can()` still says whether the call is allowed at all.

## Fave1 Plus

`ctx.user.plus` says whether this person can use Plus extras: `'plus'` — they have Plus or Ultra; `'free'` — they don’t. Signed out is `'free'`. Lock only the extras, and keep everything people need to use your app open to everyone.

`src/index.ts`

```ts
const plusOk = ctx.user.plus === 'plus';
const label = plusOk ? 'Neon theme' : 'Neon theme ✦ Plus';
```

It is a reading, not a payment — your app never sees what they pay for their plan. (Selling something inside your app is [ctx.purchases](https://developers.fave1.com/docs/ctx-purchases.md), with Fave1’s price and Buy button.)

## Which plan

`ctx.user.tier` names the plan this person is on: `'free'`, `'basic'`, `'plus'` or `'ultra'`. It is `null` when nobody is signed in, and until the first answer arrives — `await ctx.user.load()` first. In app mode an app that declares only `page.*` or `clipboard` never asks the account, so `tier` is `null` and `plus` `'free'` there even for someone signed in — declare `storage` if you need the plan in app mode. `plus` stays the switch for ✦ extras — it is `'plus'` on both Plus and Ultra.

Use `tier` only for something one plan gets on top — an Ultra extra, a bigger limit for Ultra.

`src/index.ts`

```ts
await ctx.user.load();
const ultraOk = ctx.user.tier === 'ultra';
const saves = ultraOk ? 200 : 50;
```

## Nobody signed in

`signedIn` is `false`, `id` stays `undefined` and `granted` is `false` — the same moment `ctx.can('storage')` and `ctx.can('pub')` are false. Fold what needs an account and keep the rest working — a [ctx.shared](https://developers.fave1.com/docs/ctx-shared.md) link still opens for them, read-only.

## While you build

> **The sandbox has no id.** Run from `fave1 dev` or a review link, `ctx.user.id` is `undefined` and `granted` is `true` — the sandbox never asks, and nothing there touches a real account. Switch Data to [My account](https://developers.fave1.com/docs/quickstart.md#dev-account) and both work as they will live; the id belongs to the DEV slot, so it differs from your live one.
