# Sign-in hooks

Your own code at three moments of sign-in. A hook is one of your project's [functions](https://rezincore.com/docs/functions.md), or a signed message to an address you choose. Each call has a short time limit, and you decide what a failure means.

| Hook | When | What it may do |
|---|---|---|
| Before sign-up | Before any account is made, whichever way: email and password, a provider, a phone number, a temporary account | Refuse, with a message your user is shown; note facts on the new account |
| After sign-in | Each time a sign-in opens, whichever way | Nothing; it is told, for your own records |
| Claims for a sign-in | Each time a sign-in opens, before the answer is sent | Give facts that ride on that sign-in: returned by `/v1/auth/user` and readable in access rules |

## Setting one up

Sign-in, **Sign-in hooks**. Only an owner of the company sets up or changes a hook: a hook decides who may sign up and what a sign-in carries into access rules. Other members see the hooks and the delivery log.

For each hook choose:

- **Call**: one of the project's functions, or an outside address. A function keeps everything inside Rezin Core. An outside address needs [webhooks](https://rezincore.com/docs/webhooks.md) switched on for the service, because the message carries the person's email address out; it must be public `https`, given by name, and redirects are not followed.
- **Wait at most**: 200 to 5,000 milliseconds. Two seconds unless you change it. A hook that has not answered by then has failed.
- **If it fails**: *Turn the person away* (closed, the default) or *Carry on* (open). A failure is no answer in time, an answer that is not 2xx, an answer that is not a JSON object, or an answer of the wrong shape.

**Try it with a made-up person** calls the hook with invented details and shows what came back.

An outside address gets a signing secret when it is saved, shown once. The message carries `X-Rezin-Signature: t=<seconds>,v1=<hex>`, the HMAC-SHA256 of `<t>.<body>` with that secret, exactly as for [webhooks](https://rezincore.com/docs/webhooks.md). A function needs no secret: it is called by Rezin Core alone, with `x-rezin-trigger: hook`.

## What each hook is sent and answers

Every call is a JSON `POST`. `x-rezin-hook` names the hook. A test call has `"test": true`.

### Before sign-up

```json
{ "type": "before_signup", "project": "<project ID>", "at": "2026-11-27T10:00:00.000Z",
  "signup": { "email": "sam@example.test", "phone": null, "fullName": "Sam Sample", "method": "password" },
  "ip": "203.0.113.10" }
```

`method` is `password`, `anonymous`, `phone` or the provider's name. `email` is empty for a phone number or a temporary account; `phone` is set for a phone number.

Answer `{}` or `{ "allow": true }` to let the person in. To refuse:

```json
{ "allow": false, "message": "Sign-ups are by invitation for now." }
```

The person's application is answered `403` with `signup_refused` and your message (one line, 200 characters at most). From a provider, the person is sent back to your address with `?error=signup_refused&error_description=<your message>`.

To note facts on the new account, add `"metadata": { ... }`: a JSON object of 4 KB at most. It is kept on the account and returned as `metadata` by `GET /v1/auth/user`. When the account is made later (a sign-up that waits for its address to be confirmed), the facts wait for it for a day.

### After sign-in and claims

```json
{ "type": "claims", "project": "<project ID>", "at": "2026-11-27T10:00:00.000Z",
  "user": { "id": "…", "email": "sam@example.test", "organizationId": "…", "metadata": { "plan": "gold" }, "anonymous": false },
  "method": "password", "ip": "203.0.113.10" }
```

`after_signin` has the same shape. Its answer is not read.

The claims hook answers `{ "claims": { ... } }`: a JSON object of 2 KB at most. An answer with no `claims` gives the sign-in none.

The after sign-in hook is waited for only when it is closed. Open, it is told in the background and the sign-in is answered at once.

A closed hook that fails ends the sign-in it was asked about: the application is answered `503` with `signin_unavailable`, and the token is never usable.

## Claims in access rules

The claims of the sign-in behind a request are readable in a table's access rules:

```sql
create policy gold_only on perks for select
  using ((core.app_claims() ->> 'plan') = 'gold');
```

`core.app_claims()` returns the sign-in's claims as `jsonb`, or `{}` when there are none, when a secret key acts without an account, and outside a request. The value is set by Rezin Core for the length of one request from what your hook answered when the sign-in began; nothing in a request can set or change it. Claims are fixed for the life of the sign-in: a change takes effect when the person signs in again.

What `core.app_claims()` does not see yet: [realtime](https://rezincore.com/docs/realtime.md) re-reads rows without claims, so a rule that needs a claim sends that listener nothing, and the console's **View as** check runs without claims.

## The delivery log

The newest 100 calls on the page, and 500 kept: when, which hook, how it went, the answer's status and how long it took, with a short reason when it failed. The message, the answer, the signing secret and anything about the person are never kept. Above each hook: calls, failures and refusals in the last 24 hours, the typical time and the slowest one in twenty.

## Limits

- One hook of each kind per project.
- A function hook runs like any function call, with the function's own limits; the hook's time limit is the shorter of the two for the sign-in, though the function's run may carry on to its own limit in the background.
- Hooks apply to sign-ups and sign-ins through the network API. Accounts added from the console or by an invitation are not asked about.
