Skip to content

Migrate REST APIs to tRPC for end-to-end type safety#339

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/migrate-rest-apis-to-trpc
Draft

Migrate REST APIs to tRPC for end-to-end type safety#339
Copilot wants to merge 5 commits intomainfrom
copilot/migrate-rest-apis-to-trpc

Conversation

Copy link
Contributor

Copilot AI commented Feb 16, 2026

Migrates 5 REST endpoints to tRPC procedures, providing type-safe client-server communication and eliminating runtime type mismatches.

Migrated Endpoints

Public procedures:

  • POST /api/volunteervolunteer.create - Volunteer applications with IP capture
  • POST /api/badge/validatebadge.validate - OpenBadges 3.0 credential validation

Protected procedures:

  • POST /api/proposal/[id]/actionproposal.action - Proposal state transitions
  • GET /api/admin/speakersspeakers.list - Speaker listing with conference filtering

Implementation Changes

Server:

  • Added CreateVolunteerSchema and ValidateBadgeInputSchema Zod schemas
  • Enhanced tRPC context with IP address extraction from x-forwarded-for/x-real-ip headers
  • Extracted badge validation logic to /lib/badge/validation.ts (JWT + Data Integrity Proof)

Client:

  • VolunteerForm.tsx: fetch()api.volunteer.create.useMutation()
  • SpeakerMultiSelect.tsx: fetch()api.speakers.list.useQuery() with 5min cache
  • BadgeValidator.tsx: fetch()api.badge.validate.useMutation()
// Before: Manual fetch with no type safety
const response = await fetch('/api/volunteer', {
  method: 'POST',
  body: JSON.stringify(data)
})

// After: Type-safe mutation with React Query
const createMutation = api.volunteer.create.useMutation({
  onSuccess: () => { /* ... */ }
})
createMutation.mutate(data) // TS validates data shape

Non-Migratable Endpoints

REST endpoints retained for valid technical reasons:

  • /api/proxy-image - Binary image responses
  • /api/upload/* - Multipart file uploads
  • /api/auth/* - NextAuth.js framework requirements
  • /api/webhooks/* - External service integrations

Deprecation Path

Old REST endpoints remain functional until tRPC versions are verified. Remove after testing:

  • /src/app/api/volunteer/route.ts
  • /src/app/api/proposal/[id]/action/route.ts
  • /src/app/api/admin/speakers/route.ts
  • /src/app/api/badge/validate/route.ts
Original prompt

This section details on the original issue you should resolve

<issue_title>Migrate remaining REST APIs to tRPC</issue_title>
<issue_description>Title
Migrate all the remaining REST APIs to tRPC for better client type safety.

Description
tRPC is already implemented and verified working, this migration will ensure strongly typed data across client and backend reducing chances of errors.


REST API Migration Inventory

✅ Already Migrated to tRPC / Not Migratable

API Route Status Notes
/api/trpc/[trpc] tRPC handler Core tRPC endpoint
/api/auth/[...nextauth] Framework NextAuth.js handlers (required by framework)
/api/auth/callback Framework WorkOS AuthKit callback (required by framework)
/api/upload/proposal-attachment Cannot Migrate Multipart upload (Vercel Blob) - explicitly excluded
/api/upload/speaker-image Cannot Migrate Multipart image upload
/api/admin/speaker-image Cannot Migrate Multipart image upload
/api/admin/gallery/upload Cannot Migrate Multipart gallery upload
/api/travel-support/upload-receipt Cannot Migrate Multipart receipt upload

📋 APIs to Migrate to tRPC

API Route Method Description Priority
/api/volunteer POST Create volunteer application Medium
/api/proposal/[id]/action POST Proposal status changes High
/api/admin/speakers GET List all speakers (admin) Medium
/api/admin/clear-session GET/POST Clear session cookies (dev only) Low
/api/speakers/search GET Search speakers by name/email Medium
/api/proxy-image GET Proxy images from Sanity Low
/api/badge/validate POST Validate OpenBadges credential Medium

⚠️ Public/External APIs (Should Remain REST)

These are public-facing or external APIs that need REST endpoints for interoperability:

API Route Method Reason to Keep as REST
/api/badge/issuer GET OpenBadges 3.0 spec requires HTTP endpoint
/api/badge/[badgeId]/json GET Public credential endpoint
/api/badge/[badgeId]/image GET Returns SVG binary
/api/badge/[badgeId]/download GET Returns SVG download
/api/badge/[badgeId]/verify GET Public verification endpoint
/api/badge/[badgeId]/achievement GET OpenBadges achievement endpoint
/api/badge/.well-known/jwks.json GET JWKS per RFC 7517
/api/badge/keys/[keyId] GET JWK key endpoint
/api/route GET Health check (Hello world)
/api/dev GET Dev tools (development only)
/api/dev/clear-storage GET Dev tools (development only)
/api/cron/cleanup-orphaned-blobs GET Cron job (Vercel cron)
/api/cron/sales-update GET Cron job (Vercel cron)
/api/webhooks/checkin/ticket-sold POST External webhook receiver

Summary

Category Count
Total REST API routes 29
Already tRPC/Framework 2
Cannot migrate (multipart) 5
Should remain REST (external/public) 14
To migrate to tRPC 7

Migration Tasks

  • /api/proposal/[id]/actionproposal.action (High priority)
  • /api/volunteervolunteer.create (Medium priority)
  • /api/admin/speakersspeakers.list (Medium priority)
  • /api/speakers/searchspeaker.search (Medium priority - may already exist)
  • /api/badge/validatebadge.validate (Medium priority)
  • /api/proxy-image → Consider keeping as REST (returns binary)
  • /api/admin/clear-session → Low priority (dev only)</issue_description>

<agent_instructions>Migrate all remaining REST APIs to propper tRPC APIs. Use the existing architecture for tRPC calls and make sure this is propperly implemented. Some REST endpoints needs to be kept back since they are not supported in tRPC such as multipart upload.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@vercel
Copy link

vercel bot commented Feb 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cloudnativedays Error Error Feb 16, 2026 11:46am

Request Review

Copilot AI changed the title [WIP] Migrate remaining REST APIs to tRPC for type safety Migrate REST APIs to tRPC for end-to-end type safety Feb 16, 2026
Copilot AI requested a review from Starefossen February 16, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate remaining REST APIs to tRPC

2 participants