[PR #1936] [MERGED] fix: support numeric user IDs #4079

Closed
opened 2026-03-13 11:31:41 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/1936
Author: @benkingcode
Created: 3/22/2025
Status: Merged
Merged: 3/22/2025
Merged by: @Bekacru

Base: mainHead: fix-numeric-user-ids


📝 Commits (3)

📊 Changes

10 files changed (+19 additions, -19 deletions)

View changed files

📝 packages/better-auth/src/api/routes/callback.ts (+1 -1)
📝 packages/better-auth/src/db/schema.ts (+2 -2)
📝 packages/better-auth/src/oauth2/state.ts (+1 -1)
📝 packages/better-auth/src/plugins/admin/admin.ts (+9 -9)
📝 packages/better-auth/src/plugins/api-key/routes/create-api-key.ts (+1 -1)
📝 packages/better-auth/src/plugins/api-key/routes/update-api-key.ts (+1 -1)
📝 packages/better-auth/src/plugins/organization/routes/crud-members.ts (+1 -1)
📝 packages/better-auth/src/plugins/organization/routes/crud-org.ts (+1 -1)
📝 packages/better-auth/src/plugins/organization/schema.ts (+1 -1)
📝 packages/better-auth/src/plugins/two-factor/backup-codes/index.ts (+1 -1)

📄 Description

Currently if you have a numeric user ID in your database, Better Auth mostly works, but it fails when encountering Zod schema validation. For example, when linking a social account, Zod is expecting a string for the existing user ID instead of a potential number.

To fix this I've made the Zod schema coerce ids to a string, so if they are represented as numbers in the database, they will always be transformed to strings internally.

Should close #998


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/1936 **Author:** [@benkingcode](https://github.com/benkingcode) **Created:** 3/22/2025 **Status:** ✅ Merged **Merged:** 3/22/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `fix-numeric-user-ids` --- ### 📝 Commits (3) - [`5cf3d32`](https://github.com/better-auth/better-auth/commit/5cf3d323e7d086b91ea1deabd1606cd5fd400892) Coerce string - [`d80a8ca`](https://github.com/better-auth/better-auth/commit/d80a8ca081e819904a53e9a94b01d2b5721eafab) Coerce all user ids - [`97998ed`](https://github.com/better-auth/better-auth/commit/97998ed57410a6a68864051df2383ab7015ec4ed) Fix existing link ### 📊 Changes **10 files changed** (+19 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/callback.ts` (+1 -1) 📝 `packages/better-auth/src/db/schema.ts` (+2 -2) 📝 `packages/better-auth/src/oauth2/state.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/admin/admin.ts` (+9 -9) 📝 `packages/better-auth/src/plugins/api-key/routes/create-api-key.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/api-key/routes/update-api-key.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/organization/routes/crud-members.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/organization/schema.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/two-factor/backup-codes/index.ts` (+1 -1) </details> ### 📄 Description Currently if you have a numeric user ID in your database, Better Auth mostly works, but it fails when encountering Zod schema validation. For example, when linking a social account, Zod is expecting a string for the existing user ID instead of a potential number. To fix this I've made the Zod schema coerce ids to a string, so if they are represented as numbers in the database, they will always be transformed to strings internally. Should close #998 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 11:31:41 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#4079