# Log in a person

Operation ID: `person.login`

Authenticate with Cognito USER_PASSWORD_AUTH and return access/ID tokens. The token's tenant_id claim is cross-checked against the requested tenant_id; a mismatch fails the login with 403 even though Cognito itself accepted the credentials. fhir_person_id/person_type are resolved best-effort (Redis cache, then a FHIR Person search) and may be null even on a successful login.

## Public method

`login`

Signature: `person.login(request)`

Return type: `Promise<PersonLoginResponse>`

## Authentication

Classification: **PUBLIC**

## Prerequisites

None documented.

## HTTP

`POST /auth/login`

## Path parameters

None.

## Query parameters

None.

## Body parameters

| Name | Type | Required | Format | Allowed values | Default | Nullable | Description |
|---|---|---:|---|---|---|---:|---|
| `body` | [`person.LoginRequest`](../models/person.LoginRequest.md) | No |  |  |  | Yes |  |

Request model: [`person.LoginRequest`](../models/person.LoginRequest.md)

## Request example

```json
{
  "email": "person.user@example.com",
  "password": "PasswordTest1234$",
  "tenant_id": "tenant-example-001"
}
```

## Success responses

| Status | Shape | Content type | Description |
|---|---|---|---|
| `200` | [`person.LoginResponse`](../models/person.LoginResponse.md) | application/json | Person login tokens |

## Success response examples

### 200

```json
{
  "access_token": "example-access-token",
  "cognito_sub": "00000000-0000-4000-8000-000000000000",
  "expires_in": 3600,
  "fhir_person_id": "person-example-001",
  "id_token": "example-id-token",
  "person_type": "family_member"
}
```

## Common errors

| Status | Shape | Content type | Description |
|---|---|---|---|
| `400` | [`person.ErrorResponse`](../models/person.ErrorResponse.md) | application/json | Required fields are missing |
| `401` | [`person.ErrorResponse`](../models/person.ErrorResponse.md) | application/json | Cognito rejected the credentials |
| `403` | [`person.ErrorResponse`](../models/person.ErrorResponse.md) | application/json | The token's tenant does not match the requested tenant_id |

## Error examples

### 400 — Required login fields are missing

```json
{
  "error": "email, password and tenant_id are required"
}
```

### 401 — Cognito authentication failed (sanitized example)

```json
{
  "error": "Incorrect username or password."
}
```

### 403 — The token's tenant_id claim does not match the requested tenant_id

```json
{
  "error": "Tenant mismatch"
}
```

## NodeJS / TypeScript implementation

```ts
import { HCSDK } from "@healthcloudai/hc-sdk";
import type { PersonLoginRequest } from "@healthcloudai/hc-sdk";
```

```ts
const request = {
  "email": "person.user@example.com",
  "password": "PasswordTest1234$",
  "tenant_id": "tenant-example-001"
};

const result = await person.login(request);
```

## cURL

```bash
curl -X POST \
  -H 'Content-Type: application/json' \
  -d '{"email":"person.user@example.com","password":"PasswordTest1234$","tenant_id":"tenant-example-001"}' \
  'https://dev-api-person.health.cloud/auth/login'
```

## Notes

None.

## Prepared Test Console scenario

No canonical scenario is currently associated.

## Real response

No approved real integration response is currently published. Unapproved candidates are never rendered as examples.
