Skip to content

feat(database): add signUp and changePassword to auth-js and server-js - #206

Merged
tusharpandey13 merged 10 commits into
mainfrom
feat/database-conns-impl
Jul 8, 2026
Merged

feat(database): add signUp and changePassword to auth-js and server-js#206
tusharpandey13 merged 10 commits into
mainfrom
feat/database-conns-impl

Conversation

@tusharpandey13

@tusharpandey13 tusharpandey13 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds database-connection self-service operations to the SDK:

  • auth0-auth-js: new DatabaseClient sub-client exposed as authClient.database with signUp() and changePassword(), request/response transforms (camelCase ↔ snake_case wire), id normalization (id ?? _id ?? user_id), SignUpError / ChangePasswordError (sanitized cause), and a database/ barrel export.
  • auth0-server-js: ServerClient.signUp() / changePassword() as pure passthrough — no session/state writes; resolver-mode domain resolution supported.

Design notes

  • /dbconnections/* are public endpoints: only clientId is sent (no secret/assertion).
  • changePassword returns the server's plain-text confirmation (read via response.text()).
  • Error cause is sanitized to { error, error_description, message } (parity with MfaError).

Test plan

  • npm run build — auth-js, server-js, api-js
  • npm run test:ci — auth-js 329 pass, server-js 336 pass
  • npm run lint — auth-js, server-js, api-js
  • Live-tenant POC run: signup (200, id normalized), duplicate (400 invalid_signup), weak-pw (400 invalid_password), change-password (200 plain-text)

Related PRs

  • Example app: feat/database-conns-example
  • Docs: feat/database-conns-docs

Summary by CodeRabbit

  • New Features
    • Added a database sub-client to both client and server SDKs with signUp and changePassword.
    • Introduced database request/response types, plus SignUpError and ChangePasswordError for typed failure handling.
    • Expanded top-level package exports to include database APIs.
  • Bug Fixes
    • Requests now normalize payloads consistently and include the expected telemetry header; inputs are strictly validated and server error responses map to the correct typed errors.
  • Tests
    • Added/expanded coverage for request payloads, normalization, error behavior, and resolver-mode domain handling.
  • Documentation
    • Added a database-connections example (README, env, and starter Express server).

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds database signup and password-change support to auth-js and server-js, wires it into AuthClient and ServerClient, and adds a live example app plus supporting types, errors, utilities, exports, and tests.

Changes

Database client feature

Layer / File(s) Summary
Types and errors
packages/auth0-auth-js/src/database/types.ts, packages/auth0-auth-js/src/database/errors.ts, packages/auth0-auth-js/src/database/errors.spec.ts, packages/auth0-auth-js/src/database/index.ts
Defines database request and response types, database error classes, and their re-exports.
Request and response utilities
packages/auth0-auth-js/src/database/utils.ts, packages/auth0-auth-js/src/database/utils.spec.ts
Implements field validation, request transformation, response normalization, and error-body parsing, with unit tests for mapping and validation cases.
DatabaseClient implementation
packages/auth0-auth-js/src/database/database-client.ts, packages/auth0-auth-js/src/database/database-client.spec.ts
Implements DatabaseClient request execution for signup and password change, including shared POST handling and MSW-backed tests for success and error flows.
AuthClient wiring and exports
packages/auth0-auth-js/src/auth-client.ts, packages/auth0-auth-js/src/index.ts, packages/auth0-auth-js/src/auth-client.spec.ts
Adds AuthClient.database, wires the sub-client in the constructor, re-exports database symbols from auth-js, and tests the new telemetry-bearing calls.
Server database client
packages/auth0-server-js/src/database/types.ts, packages/auth0-server-js/src/database/server-database-client.ts, packages/auth0-server-js/src/database/index.ts, packages/auth0-server-js/src/server-client.ts, packages/auth0-server-js/src/types.ts, packages/auth0-server-js/src/index.ts, packages/auth0-server-js/src/database/server-database-client.spec.ts, packages/auth0-server-js/src/server-client.spec.ts
Defines the server database client options, wraps AuthClient.database behind domain resolution, and re-exports the server database surface with tests.
Example harness
examples/database-conns/.env.example, examples/database-conns/README.md, examples/database-conns/package.json, examples/database-conns/src/auth0.ts, examples/database-conns/src/index.ts, examples/database-conns/tsconfig.json
Creates the database-conns example package, its environment and build configuration, the Auth0 setup module, the Express routes, and the README instructions.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: Piyush-85, nandan-bhat

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding signUp and changePassword database operations to auth-js and server-js.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/database-conns-impl

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/auth0-auth-js/src/database/database-client.ts (1)

20-26: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Unwrapped response.json() can leak a non-SignUpError rejection.

On a 2xx response with an empty or non-JSON body, Line 24 throws a raw SyntaxError, bypassing the typed SignUpError contract that #post otherwise guarantees. Consider wrapping the parse so callers always get a SignUpError.

♻️ Proposed guard
     const response = await this.#post('/dbconnections/signup', body, SignUpError, 'Failed to sign up');
-    const raw = (await response.json()) as Record<string, unknown>;
-    return normalizeSignUpResult(raw);
+    let raw: Record<string, unknown>;
+    try {
+      raw = (await response.json()) as Record<string, unknown>;
+    } catch {
+      throw new SignUpError('Failed to sign up: invalid response body.');
+    }
+    return normalizeSignUpResult(raw);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/auth0-auth-js/src/database/database-client.ts` around lines 20 - 26,
The sign-up flow in database-client’s signUp method can leak a raw SyntaxError
from response.json() instead of the expected SignUpError. Wrap the JSON parsing
and normalize any parse failure into SignUpError, keeping the typed error
contract consistent with `#post` and the existing signUp/normalizeSignUpResult
path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/auth0-auth-js/src/database/database-client.ts`:
- Around line 20-26: The sign-up flow in database-client’s signUp method can
leak a raw SyntaxError from response.json() instead of the expected SignUpError.
Wrap the JSON parsing and normalize any parse failure into SignUpError, keeping
the typed error contract consistent with `#post` and the existing
signUp/normalizeSignUpResult path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8096c958-4249-4ca4-beef-804d669f25b4

📥 Commits

Reviewing files that changed from the base of the PR and between 8172aea and 0e51185.

📒 Files selected for processing (15)
  • packages/auth0-auth-js/src/auth-client.spec.ts
  • packages/auth0-auth-js/src/auth-client.ts
  • packages/auth0-auth-js/src/database/database-client.spec.ts
  • packages/auth0-auth-js/src/database/database-client.ts
  • packages/auth0-auth-js/src/database/errors.spec.ts
  • packages/auth0-auth-js/src/database/errors.ts
  • packages/auth0-auth-js/src/database/index.ts
  • packages/auth0-auth-js/src/database/types.ts
  • packages/auth0-auth-js/src/database/utils.spec.ts
  • packages/auth0-auth-js/src/database/utils.ts
  • packages/auth0-auth-js/src/index.ts
  • packages/auth0-server-js/src/index.ts
  • packages/auth0-server-js/src/server-client.spec.ts
  • packages/auth0-server-js/src/server-client.ts
  • packages/auth0-server-js/src/types.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/auth0-server-js/src/server-client.ts (1)

139-153: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Duplicate domain-resolution logic between database getter and top-level signUp/changePassword.

ServerDatabaseClient.signUp/changePassword (wired at Line 217-220) already implement resolveDomaingetAuthClient(domain).database.*. The new signUp/changePassword methods at Lines 1174-1177 and 1189-1192 re-implement the exact same two lines instead of delegating to this.#databaseClient. If the domain-resolution or error-wrapping logic in ServerDatabaseClient changes later, these two entry points can silently diverge.

♻️ Delegate to the existing sub-client
   public async signUp(options: SignUpOptions, storeOptions?: TStoreOptions): Promise<SignUpResult> {
-    const domain = await this.#resolveDomain(storeOptions);
-    return this.#getAuthClient(domain).database.signUp(options);
+    return this.#databaseClient.signUp(options, storeOptions);
   }
   public async changePassword(options: ChangePasswordOptions, storeOptions?: TStoreOptions): Promise<string> {
-    const domain = await this.#resolveDomain(storeOptions);
-    return this.#getAuthClient(domain).database.changePassword(options);
+    return this.#databaseClient.changePassword(options, storeOptions);
   }

Also applies to: 1163-1192

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/auth0-server-js/src/server-client.ts` around lines 139 - 153, The
top-level signUp and changePassword methods duplicate the domain-resolution and
Auth0 call logic already handled by ServerDatabaseClient. Update ServerClient to
delegate those methods to this.#databaseClient.signUp and
this.#databaseClient.changePassword instead of reimplementing
resolveDomain/getAuthClient(domain).database.* so the shared
ServerDatabaseClient behavior stays consistent.
🧹 Nitpick comments (1)
examples/database-conns/src/index.ts (1)

5-6: 🔒 Security & Privacy | 🔵 Trivial | 💤 Low value

Missing Helmet security headers.

Static analysis flags the Express app for lacking Helmet. Low risk for a local example, but since example code is often copy-pasted into real projects, adding it costs little.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/database-conns/src/index.ts` around lines 5 - 6, The Express app
setup in the app initialization block is missing Helmet security headers. Add
Helmet middleware alongside the existing express.json() middleware by importing
helmet and registering it on the Express instance early in the setup so copied
example code includes basic security hardening.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/auth0-server-js/src/server-client.ts`:
- Around line 139-153: The top-level signUp and changePassword methods duplicate
the domain-resolution and Auth0 call logic already handled by
ServerDatabaseClient. Update ServerClient to delegate those methods to
this.#databaseClient.signUp and this.#databaseClient.changePassword instead of
reimplementing resolveDomain/getAuthClient(domain).database.* so the shared
ServerDatabaseClient behavior stays consistent.

---

Nitpick comments:
In `@examples/database-conns/src/index.ts`:
- Around line 5-6: The Express app setup in the app initialization block is
missing Helmet security headers. Add Helmet middleware alongside the existing
express.json() middleware by importing helmet and registering it on the Express
instance early in the setup so copied example code includes basic security
hardening.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 70e81f4d-980d-4e5f-a40e-16e4e39de081

📥 Commits

Reviewing files that changed from the base of the PR and between 5a87d5d and 14d0952.

📒 Files selected for processing (7)
  • examples/database-conns/.env.example
  • examples/database-conns/README.md
  • examples/database-conns/package.json
  • examples/database-conns/src/auth0.ts
  • examples/database-conns/src/index.ts
  • examples/database-conns/tsconfig.json
  • packages/auth0-server-js/src/server-client.ts
✅ Files skipped from review due to trivial changes (3)
  • examples/database-conns/tsconfig.json
  • examples/database-conns/src/auth0.ts
  • examples/database-conns/README.md

Piyush-85
Piyush-85 previously approved these changes Jul 3, 2026

@Piyush-85 Piyush-85 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, reviewed internally.

tusharpandey13 and others added 10 commits July 8, 2026 17:28
Replace flat serverClient.signUp/changePassword with serverClient.database.*
(new ServerDatabaseClient), matching the mfa/passkey sub-client pattern and the
auth0-auth-js authClient.database surface. Disambiguates that these operate on
database connections.
Accept either email or username on changePassword (username-only DB
connections); require at least one and forward both on the wire when
present. Widen SignUpResult.userMetadata to Record<string, unknown>
since server output may be non-string, and note deferred phone_number
signUp support behind the fuji connection-attribute feature flag.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…nge-password

Signed re-add of the database-conns example that previously entered the
branch via an unsigned upstream merge lineage. Content matches the
validated PR tree.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/database-conns/src/index.ts`:
- Around line 27-29: The change-password route is passing req.body.email
directly into auth0.database.changePassword without validating it first, which
can lead to a confusing SDK error. Update the /change-password handler in the
app.post callback to check for a present email before calling
auth0.database.changePassword, and return a clear client error response when it
is missing, following the same validation pattern used in the /signup flow.
- Around line 9-15: Add a minimal request-body guard before calling the SDK in
the /signup and /change-password handlers so missing email or password returns a
clear 400 response instead of an opaque SDK failure. Update the route handlers
in index.ts around auth0.database.signUp and auth0.database.changePassword to
validate req.body.email and req.body.password first, and short-circuit with a
simple client error response if either value is absent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: dfe3e772-7c3a-40c1-ba09-5c37e8821dfb

📥 Commits

Reviewing files that changed from the base of the PR and between 14d0952 and 0fc6203.

📒 Files selected for processing (25)
  • examples/database-conns/.env.example
  • examples/database-conns/README.md
  • examples/database-conns/package.json
  • examples/database-conns/src/auth0.ts
  • examples/database-conns/src/index.ts
  • examples/database-conns/tsconfig.json
  • packages/auth0-auth-js/src/auth-client.spec.ts
  • packages/auth0-auth-js/src/auth-client.ts
  • packages/auth0-auth-js/src/database/database-client.spec.ts
  • packages/auth0-auth-js/src/database/database-client.ts
  • packages/auth0-auth-js/src/database/errors.spec.ts
  • packages/auth0-auth-js/src/database/errors.ts
  • packages/auth0-auth-js/src/database/index.ts
  • packages/auth0-auth-js/src/database/types.ts
  • packages/auth0-auth-js/src/database/utils.spec.ts
  • packages/auth0-auth-js/src/database/utils.ts
  • packages/auth0-auth-js/src/index.ts
  • packages/auth0-server-js/src/database/index.ts
  • packages/auth0-server-js/src/database/server-database-client.spec.ts
  • packages/auth0-server-js/src/database/server-database-client.ts
  • packages/auth0-server-js/src/database/types.ts
  • packages/auth0-server-js/src/index.ts
  • packages/auth0-server-js/src/server-client.spec.ts
  • packages/auth0-server-js/src/server-client.ts
  • packages/auth0-server-js/src/types.ts
✅ Files skipped from review due to trivial changes (5)
  • examples/database-conns/package.json
  • packages/auth0-server-js/src/index.ts
  • examples/database-conns/README.md
  • examples/database-conns/tsconfig.json
  • packages/auth0-auth-js/src/database/types.ts
🚧 Files skipped from review as they are similar to previous changes (17)
  • packages/auth0-auth-js/src/database/index.ts
  • packages/auth0-server-js/src/database/types.ts
  • packages/auth0-auth-js/src/index.ts
  • packages/auth0-auth-js/src/auth-client.spec.ts
  • packages/auth0-server-js/src/database/server-database-client.spec.ts
  • packages/auth0-server-js/src/types.ts
  • packages/auth0-auth-js/src/database/errors.spec.ts
  • examples/database-conns/src/auth0.ts
  • packages/auth0-auth-js/src/auth-client.ts
  • packages/auth0-auth-js/src/database/utils.spec.ts
  • packages/auth0-server-js/src/server-client.ts
  • packages/auth0-server-js/src/database/server-database-client.ts
  • packages/auth0-auth-js/src/database/utils.ts
  • packages/auth0-server-js/src/server-client.spec.ts
  • packages/auth0-server-js/src/database/index.ts
  • packages/auth0-auth-js/src/database/database-client.ts
  • packages/auth0-auth-js/src/database/database-client.spec.ts

Comment on lines +9 to +15
app.post('/signup', async (req, res) => {
try {
const result = await auth0.database.signUp({
email: req.body.email,
password: req.body.password,
connection,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Add basic input validation before calling the SDK.

Both /signup and /change-password pass req.body.email (and req.body.password) directly to the SDK without checking for presence. If either is undefined, the SDK call will fail with an opaque error rather than a clear 400 response. Since this is an example app that users may copy as a starting pattern, adding a minimal guard improves the pattern being set.

💚 Proposed validation guard
 app.post('/signup', async (req, res) => {
+  const { email, password } = req.body;
+  if (!email || !password) {
+    return res.status(400).json({ ok: false, message: 'email and password are required' });
+  }
   try {
     const result = await auth0.database.signUp({
-      email: req.body.email,
-      password: req.body.password,
+      email,
+      password,
       connection,
     });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
app.post('/signup', async (req, res) => {
try {
const result = await auth0.database.signUp({
email: req.body.email,
password: req.body.password,
connection,
});
app.post('/signup', async (req, res) => {
const { email, password } = req.body;
if (!email || !password) {
return res.status(400).json({ ok: false, message: 'email and password are required' });
}
try {
const result = await auth0.database.signUp({
email,
password,
connection,
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/database-conns/src/index.ts` around lines 9 - 15, Add a minimal
request-body guard before calling the SDK in the /signup and /change-password
handlers so missing email or password returns a clear 400 response instead of an
opaque SDK failure. Update the route handlers in index.ts around
auth0.database.signUp and auth0.database.changePassword to validate
req.body.email and req.body.password first, and short-circuit with a simple
client error response if either value is absent.

Comment on lines +27 to +29
app.post('/change-password', async (req, res) => {
try {
const message = await auth0.database.changePassword({ email: req.body.email, connection });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Validate email presence in the change-password route.

Same concern as /signupreq.body.email is passed unvalidated. A missing email will produce a confusing SDK error instead of a clear client error.

💚 Proposed validation guard
 app.post('/change-password', async (req, res) => {
+  const { email } = req.body;
+  if (!email) {
+    return res.status(400).json({ ok: false, message: 'email is required' });
+  }
   try {
-    const message = await auth0.database.changePassword({ email: req.body.email, connection });
+    const message = await auth0.database.changePassword({ email, connection });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
app.post('/change-password', async (req, res) => {
try {
const message = await auth0.database.changePassword({ email: req.body.email, connection });
app.post('/change-password', async (req, res) => {
const { email } = req.body;
if (!email) {
return res.status(400).json({ ok: false, message: 'email is required' });
}
try {
const message = await auth0.database.changePassword({ email, connection });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/database-conns/src/index.ts` around lines 27 - 29, The
change-password route is passing req.body.email directly into
auth0.database.changePassword without validating it first, which can lead to a
confusing SDK error. Update the /change-password handler in the app.post
callback to check for a present email before calling
auth0.database.changePassword, and return a clear client error response when it
is missing, following the same validation pattern used in the /signup flow.

@tusharpandey13
tusharpandey13 merged commit 8725819 into main Jul 8, 2026
16 checks passed
@tusharpandey13
tusharpandey13 deleted the feat/database-conns-impl branch July 8, 2026 12:13
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.

2 participants