Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/auth/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,18 @@
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;

Check warning on line 162 in src/auth/database.ts

View workflow job for this annotation

GitHub Actions / Type Check

Unexpected any. Specify a different type

Check warning on line 162 in src/auth/database.ts

View workflow job for this annotation

GitHub Actions / Lint & Format

Unexpected any. Specify a different type
// 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<SignUpResponse>;
}

/**
Expand Down
32 changes: 32 additions & 0 deletions tests/auth/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,38 @@ describe("Database", () => {
});
expect(data).toEqual({
_id: "test-id",
id: "test-id",
email_verified: false,
email,
});
});

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,
});
Expand Down
34 changes: 34 additions & 0 deletions tests/auth/fixtures/database.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading