Repository: better-auth/better-auth (2025-08-23T14:14:12Z)

Issue:
auth.api.listUserAccounts return type field naming and type are inconsistent with usage in other areas
### Is this suited for github?

- [x] Yes, this is suited for github

### To Reproduce

The return type of `auth.api.listUserAccounts` is a list of accounts belonging to the user. The `provider` field shows the providerId of the account, but isn't named as such. The type could possibly also be improved? Other areas of BetterAuth have a well-typed `providerId` field, instead of just a `string`

### Current vs. Expected behavior

Change the name to `providerId`, and possibly narrow the string type to the actual providers

### What version of Better Auth are you using?

1.3.7

### System info

```bash
N/A
```

### Which area(s) are affected? (Select all that apply)

Types

### Auth config (if applicable)

```typescript
N/A
```

### Additional context

_No response_


Discussion:
<!-- Greeting -->
Hi @SkepticMystic! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team.

<!-- Answer -->
You're right—there's an inconsistency: `auth.api.listUserAccounts` returns accounts with a `provider` field (typed as a generic string), while other areas of Better Auth use `providerId` and often narrow its type to a union of supported provider strings for better type safety. The database schema, OAuth plugin configs, and API endpoints all consistently use `providerId` as the field name and type, which makes migration straightforward and beneficial for clarity and maintainability [[docs](https://better-auth.com/docs/concepts/database)].

To align with the rest of the codebase, consider renaming the field to `providerId` and using an existing provider ID type (such as a union of string literals or an enum) instead of a plain string. This will improve type safety and developer experience. There’s ongoing work to improve providerId type consistency in related areas, but this specific naming issue hasn’t been addressed yet [[PR #3712](https://github.com/better-auth/better-auth/pull/3712)].


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? [Good](https://app.dosu.dev/response-feedback/202c0b00-6582-475c-9948-17a5c7c7d4ec?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/202c0b00-6582-475c-9948-17a5c7c7d4ec?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/202c0b00-6582-475c-9948-17a5c7c7d4ec?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/202c0b00-6582-475c-9948-17a5c7c7d4ec?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/202c0b00-6582-475c-9948-17a5c7c7d4ec?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/202c0b00-6582-475c-9948-17a5c7c7d4ec?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/202c0b00-6582-475c-9948-17a5c7c7d4ec?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4174)



Patch:
diff --git a/packages/better-auth/src/api/routes/account.ts b/packages/better-auth/src/api/routes/account.ts
index 2ae1811ae6..fd8443c7b9 100644
--- a/packages/better-auth/src/api/routes/account.ts
+++ b/packages/better-auth/src/api/routes/account.ts
@@ -36,7 +36,7 @@ export const listUserAccounts = createAuthEndpoint(
 											id: {
 												type: "string",
 											},
-											provider: {
+											providerId: {
 												type: "string",
 											},
 											createdAt: {
@@ -47,25 +47,25 @@ export const listUserAccounts = createAuthEndpoint(
 												type: "string",
 												format: "date-time",
 											},
-										},
-										accountId: {
-											type: "string",
-										},
-										scopes: {
-											type: "array",
-											items: {
+											accountId: {
 												type: "string",
 											},
+											scopes: {
+												type: "array",
+												items: {
+													type: "string",
+												},
+											},
 										},
+										required: [
+											"id",
+											"providerId",
+											"createdAt",
+											"updatedAt",
+											"accountId",
+											"scopes",
+										],
 									},
-									required: [
-										"id",
-										"provider",
-										"createdAt",
-										"updatedAt",
-										"accountId",
-										"scopes",
-									],
 								},
 							},
 						},
@@ -82,7 +82,7 @@ export const listUserAccounts = createAuthEndpoint(
 		return c.json(
 			accounts.map((a) => ({
 				id: a.id,
-				provider: a.providerId,
+				providerId: a.providerId,
 				createdAt: a.createdAt,
 				updatedAt: a.updatedAt,
 				accountId: a.accountId,


Test patch:
diff --git a/packages/better-auth/src/api/routes/account.test.ts b/packages/better-auth/src/api/routes/account.test.ts
index b3a5f4bfb2..4332159dfc 100644
--- a/packages/better-auth/src/api/routes/account.test.ts
+++ b/packages/better-auth/src/api/routes/account.test.ts
@@ -349,9 +349,9 @@ describe("account", async () => {
 
 		const accountToUnlink = previousAccounts.data![0];
 		const unlinkAccountId = accountToUnlink.accountId;
-		const providerId = accountToUnlink.provider;
+		const providerId = accountToUnlink.providerId;
 		const accountsWithSameProvider = previousAccounts.data!.filter(
-			(account) => account.provider === providerId,
+			(account) => account.providerId === providerId,
 		);
 		if (accountsWithSameProvider.length <= 1) {
 			return;
@@ -412,7 +412,7 @@ describe("account", async () => {
 		});
 
 		const googleAccounts = previousAccounts.data!.filter(
-			(account) => account.provider === "google",
+			(account) => account.providerId === "google",
 		);
 		expect(googleAccounts.length).toBeGreaterThan(1);
 
@@ -434,7 +434,7 @@ describe("account", async () => {
 		});
 
 		const remainingGoogleAccounts = accountsAfterUnlink.data!.filter(
-			(account) => account.provider === "google",
+			(account) => account.providerId === "google",
 		);
 		expect(remainingGoogleAccounts.length).toBe(1);
 	});