Identity
Source: src/data/identity/
Service
createIdentityService / IdentityService
Factory: createIdentityService(repo: IdentityRepository) — returns IdentityService.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| linkIdentity | (ctx: RequestContext, input: { userId: string, tenantId?: string, provider: string, providerUserId: string, profile?: Record<string, unknown>, secrets?: Record<string, unknown> }) | Promise<IdentityRecord> | Links an external identity to a user; upserts if the provider+providerUserId+tenant combination already exists |
| listUserIdentities | (ctx: RequestContext, userId: string) | Promise<IdentityRecord[]> | Lists all linked identities for a user |
Repository
IdentityRepository
| Method | Parameters | Returns |
|---|---|---|
| getById | (ctx: RequestContext, id: string) | Promise<IdentityRecord | null> |
| findByProviderIdentity | (provider: string, providerUserId: string, tenantId?: string) | Promise<IdentityRecord | null> |
| listByUser | (ctx: RequestContext, userId: string) | Promise<IdentityRecord[]> |
| create | (ctx: RequestContext, input: IdentityCreateInput) | Promise<IdentityRecord> |
| update | (ctx: RequestContext, id: string, patch: Partial<IdentityCreateInput>) | Promise<IdentityRecord> |
IdentityRecord
| Field | Type |
|---|---|
| id | string |
| userId | string |
| tenantId | string (optional) |
| provider | string |
| providerUserId | string |
| profile | Record<string, unknown> |
| secrets | Record<string, unknown> (optional) |
| createdAt | Date |
| updatedAt | Date |
Validators
identitySchema
| Field | Type | Required | Default |
|---|---|---|---|
| userId | string | Yes | — |
| tenantId | string | No | — |
| provider | string | Yes | — |
| providerUserId | string | Yes | — |
| profile | Record<string, unknown> | No | {} |
| secrets | Record<string, unknown> | No | — |
Inferred Types
Identity—z.infer<typeof identitySchema>