Skip to content

refactor-registry-low-priority-1: Add Zod validation for Clerk API responses #43

@shwetank-dev

Description

@shwetank-dev

Summary

The auth plugin (src/plugins/auth.ts) trusts Clerk's API response without runtime validation. Fields are extracted via TypeScript as casts, which provide no runtime safety.

If Clerk changes their API shape, we get silent undefined propagation instead of a clear error.

Proposed changes

  • Define a Zod schema for the Clerk user fields we use (emailAddresses, externalAccounts, publicMetadata, etc.)
  • Parse the clerkClient.users.getUser() response through it
  • Remove unsafe as unknown as Record<string, unknown> casts
  • Applies to both apps/registry/src/plugins/auth.ts and apps/registryDemo/src/plugins/auth.ts

Rationale

Best practice: validate at system boundaries. Clerk is an external service — its responses are untrusted input.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions