From 3a46624f2f39b1f2cacfac2c402fba053c5bb5f9 Mon Sep 17 00:00:00 2001 From: tanya732 Date: Thu, 18 Sep 2025 10:42:49 +0530 Subject: [PATCH 1/3] Fix: id field in SignUpResponse --- src/auth/database.ts | 13 ++++++++++++- tests/auth/database.test.ts | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/auth/database.ts b/src/auth/database.ts index 5124f5101f..d19cb305b1 100644 --- a/src/auth/database.ts +++ b/src/auth/database.ts @@ -155,7 +155,18 @@ export class Database extends BaseAuthAPI { initOverrides, ); - return JSONApiResponse.fromResponse(response); + // Transform the response to ensure id field is always available + const jsonResponse = await JSONApiResponse.fromResponse(response); + + if (jsonResponse.data) { + const data = jsonResponse.data as any; + // Map _id or user_id to id + if (!data.id && (data._id || data.user_id)) { + data.id = data._id || data.user_id; + } + } + + return jsonResponse as JSONApiResponse; } /** diff --git a/tests/auth/database.test.ts b/tests/auth/database.test.ts index c893119ba7..3ab57a1de6 100644 --- a/tests/auth/database.test.ts +++ b/tests/auth/database.test.ts @@ -34,7 +34,7 @@ describe("Database", () => { connection: "Username-Password-Authentication", }); expect(data).toEqual({ - _id: "test-id", + id: "test-id", email_verified: false, email, }); From caf53ade074ceb89ebc52fb3bc9aab088273d59d Mon Sep 17 00:00:00 2001 From: tanya732 Date: Thu, 18 Sep 2025 11:10:00 +0530 Subject: [PATCH 2/3] Updated tests --- tests/auth/database.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auth/database.test.ts b/tests/auth/database.test.ts index 3ab57a1de6..8e9bfebb65 100644 --- a/tests/auth/database.test.ts +++ b/tests/auth/database.test.ts @@ -34,6 +34,7 @@ describe("Database", () => { connection: "Username-Password-Authentication", }); expect(data).toEqual({ + _id: "test-id", id: "test-id", email_verified: false, email, From d1fd7edda070a7a5a57d6cc83775f096b82cb221 Mon Sep 17 00:00:00 2001 From: tanya732 Date: Tue, 23 Sep 2025 08:57:45 +0530 Subject: [PATCH 3/3] Updated tests --- tests/auth/database.test.ts | 31 ++++++++++++++++++++++++++++ tests/auth/fixtures/database.json | 34 +++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/tests/auth/database.test.ts b/tests/auth/database.test.ts index 8e9bfebb65..7b2373afc0 100644 --- a/tests/auth/database.test.ts +++ b/tests/auth/database.test.ts @@ -41,6 +41,37 @@ describe("Database", () => { }); }); + it("should signup a user when response param for id is 'user_id'", async () => { + const database = new Database(opts); + const email = "test-email-1@example.com"; + const { data } = await database.signUp({ + email, + password: PASSWORD, + connection: "Username-Password-Authentication", + }); + expect(data).toEqual({ + user_id: "test-id", + id: "test-id", + email_verified: false, + email, + }); + }); + + it("should signup a user when response param for id is 'id'", async () => { + const database = new Database(opts); + const email = "test-email-2@example.com"; + const { data } = await database.signUp({ + email, + password: PASSWORD, + connection: "Username-Password-Authentication", + }); + expect(data).toEqual({ + id: "test-id", + email_verified: false, + email, + }); + }); + it("should require connection", async () => { const database = new Database(opts); await expect( diff --git a/tests/auth/fixtures/database.json b/tests/auth/fixtures/database.json index 39f84c9a6f..a00a4b7ab5 100644 --- a/tests/auth/fixtures/database.json +++ b/tests/auth/fixtures/database.json @@ -33,6 +33,40 @@ "email": "test-email@example.com" } }, + { + "scope": "https://test-domain.auth0.com", + "method": "POST", + "path": "/dbconnections/signup", + "body": { + "client_id": "test-client-id", + "email": "test-email-1@example.com", + "password": "test-password", + "connection": "Username-Password-Authentication" + }, + "status": 200, + "response": { + "user_id": "test-id", + "email_verified": false, + "email": "test-email-1@example.com" + } + }, + { + "scope": "https://test-domain.auth0.com", + "method": "POST", + "path": "/dbconnections/signup", + "body": { + "client_id": "test-client-id", + "email": "test-email-2@example.com", + "password": "test-password", + "connection": "Username-Password-Authentication" + }, + "status": 200, + "response": { + "id": "test-id", + "email_verified": false, + "email": "test-email-2@example.com" + } + }, { "scope": "https://test-domain.auth0.com", "method": "POST",