# logic.if

Sends the payload down true or false by a condition

# logic.if

```
logic.if --when EXPR
```

Sends the payload down `true` or `false` by a condition. Evaluates `--when` (JavaScript over `input`, `$trigger`, `$nodes`) and sends the payload, unchanged, down the `true` pin or the `false` pin. This is how a pipeline validates, guards and answers 404/400: wire `[b]:true -> [c]` and `[b]:false -> [e]` in graph mode — in pipe mode only `true` continues and `false` ends the run silently. The pin not taken is skipped, and so is every node only it feeds (`$nodes` of a skipped node is `null`). The expression sees the payload as `input` (right after a webhook, `input.webhook.body.x`; anywhere, `$trigger.body.x`), not `$input`.

## Flags

- `--when` (required): JavaScript over `input` (and `$trigger`, `$nodes`): truthy routes to the `true` pin, falsy to `false`.

## Examples

### Guard a form field

```
| logic.if --when "typeof $trigger.body?.title === 'string' && $trigger.body.title.length > 0"
```

`true` carries the same payload on; wire `false` to a `web.response.send --status 400`.

### Found or not found

```
| logic.if --when "input.query.rows.length > 0"
```

Fires the `false` pin; the payload is unchanged.

Input:

```json
{
  "query": {
    "rows": []
  }
}
```

## Used in

- [Auth and Authorization](/examples/auth-and-authorization.md)
- [Blog with Admin](/examples/blog-with-admin.md)
- [Cookie + JWT Authentication](/examples/cookie-jwt-auth.md)
- [Forum with Real-Time Chat](/examples/forum-with-chat.md)
- [Sign in with Google (OAuth login)](/examples/oauth-login-google.md)
- [Real-Time Game (WebSocket State Sync)](/examples/realtime-game.md)
- [Web Scraping + Data Pipeline](/examples/scraping.md)
- [TTS API + Frontend Page](/examples/tts-with-page.md)
- [Webhook → TSX Page](/examples/webhook-page-tsx.md)
- [REST API + PostgreSQL](/examples/webhook-restapi-postgres.md)
