# Identity Reuse Module

This guide is specific to Web SDK 2.0. If you are still using 1.x, you can find documentation [here](https://developer.incode.com/docs/web-sdk-reference). Contact your Incode Representative for upgrade information and check if you are a candidate for this upgrade.

Full rollout to all clients still TBD.

The Identity Reuse module recognizes a returning user by matching their selfie against existing on-file biometric records, then offering them the choice to reuse the existing identity (skipping fresh ID + selfie capture) or proceed with a new verification.

Follows the [form-based pattern](https://developer.incode.com/docs/web-sdk-2-module-patterns#1-form-based-modules) with selection sub-states. The user reviews candidate matches and submits their choice. See the patterns page for the shared lifecycle.

## Tag

`<incode-identity-reuse>` is a standard Web Component. Importing the UI subpath registers the custom element; importing the CSS applies the module's styles.

```ts
import '@incodetech/web/identity-reuse';
import '@incodetech/web/identity-reuse/styles.css';
```

## Properties

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `config` | `IdentityReuseConfig` | ❌ | No options |
| `onFinish` | `() => void` | ❌ | Called when the user's choice is submitted |
| `onError` | `(error: string) => void` | ❌ | Called when an error occurs |

## Configuration

The module takes no configuration:

```typescript
type IdentityReuseConfig = {};
```

Candidate sources (which prior identities are considered) are configured server-side.

## State Machine

`IdentityReuseState` is a discriminated union over `status`. The selection states (`oneCandidateFound`, `multiCandidatesFound`, `noCandidatesFound`) are unique to this module:

| Status | Description |
| --- | --- |
| `idle` | Initial state. |
| `loading` | Fetching candidate matches from the backend. |
| `oneCandidateFound` | Single match found. User confirms or rejects. |
| `multiCandidatesFound` | Multiple matches; user picks one (or skips). |
| `noCandidatesFound` | No matches; user proceeds with a fresh verification. |
| `submitContinue` | User chose to reuse a candidate; submitting the choice. |
| `submitSkip` | User chose to skip reuse; submitting the skip. |
| `finished` | Terminal. |
| `error` | Fatal error. |

The candidate states expose `currentOrganizationName` and `candidateOrganizationNames` from the backend response.

## API Methods

| Method | Purpose |
| --- | --- |
| `load()` | Fetch candidate matches. |
| `startSelection()` | Begin selecting from `multiCandidatesFound`. |
| `chooseCandidate(organizationName)` | Pick a candidate by organization name. |
| `changeCandidate()` | Go back to selection from `submitContinue` (before submit). |
| `submitCandidate()` | Submit the chosen candidate (reuse). |
| `skip()` | Skip reuse and proceed with fresh verification. |
| `retry()` | After `error`, restart. |

Plus the universal lifecycle: `subscribe`, `getState`, `reset`, `stop`.
