# Use a sign-in link

Turn the token from a sign-in link into a session on this device.

POST `/api/v1/sign-in/redeem`

**cURL**

```shell
curl -X POST 'https://www.prufy.dev/api/v1/sign-in/redeem' \
  -H 'content-type: application/json' \
  -d '{
  "token": "cN4vR7pQ2sT9wX1yZ5aB8dE3fG6hJ0kL4mP7qS2uV9w"
}'
```

**Node.js**

```javascript
const response = await fetch("https://www.prufy.dev/api/v1/sign-in/redeem", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ token: "cN4vR7pQ2sT9wX1yZ5aB8dE3fG6hJ0kL4mP7qS2uV9w" }),
})
const data = await response.json()
```

**Python**

```python
import requests

response = requests.post(
    "https://www.prufy.dev/api/v1/sign-in/redeem",
    json={"token": "cN4vR7pQ2sT9wX1yZ5aB8dE3fG6hJ0kL4mP7qS2uV9w"},
)
data = response.json()
```

Response 200 OK

```json
{
  "signedIn": true,
  "terminalCode": null
}
```

The page the email opens calls this when its button is pressed. On success the response sets the session cookie, and this device is one more session on the account. A device that was signed in to a different account ends that session: its claims stay on that account, and nothing moves between accounts.

`signedIn` is false when the token is unknown, used, expired, or the account's address has changed or been removed since the link was sent. That's still a 200.

For a link a terminal asked for, nobody is signed in: `terminalCode` is the code to type into that terminal.

## Authentication

No cookie. The token in the request is the whole credential. [How sessions work](https://www.prufy.dev/docs/authentication.md).

## Body

JSON, with `content-type: application/json`.

- `token` string required

  The token from the emailed link.

  - At most 200 characters

## Response

`200 OK`, with every field below present. Times are ISO 8601 strings in UTC.

- `signedIn` boolean

  True when this device is now signed in. False when the link didn't work.
- `terminalCode` string | null

  For a link a terminal asked for: the code to type into it. Null otherwise. Nobody is signed in until the terminal sends it.

## Errors

| Status | Kind | When |
| --- | --- | --- |
| 400 | `bad_request` | The body isn't JSON, or doesn't match the shape below. `message` names the first field to fix, and `fields` lists each one with its path. |
| 413 | `payload_too_large` | The body is over 16 KB. No route takes anything near that. |
| 429 | `rate_limited` | This network has used 30 links and codes in the last hour. |

Any route can also answer `500` with `internal_error`. Every error has the same shape, described in [Errors](https://www.prufy.dev/docs/errors.md).

---

Every page of these docs, as a list: https://www.prufy.dev/llms.txt
