Skip to content

Auth and registration for local dev#475

Open
artemdemo wants to merge 1 commit intomainfrom
auth-and-stuff
Open

Auth and registration for local dev#475
artemdemo wants to merge 1 commit intomainfrom
auth-and-stuff

Conversation

@artemdemo
Copy link
Copy Markdown
Contributor

@artemdemo artemdemo commented Apr 12, 2026

Note

Description

Adds a local authentication router to the base44 dev server, enabling developers to test registration, OTP verification, and login flows locally without hitting the production API. The auth router issues JWT tokens signed with a local secret and stores user credentials in a private in-memory NeDB collection, keeping sensitive data (passwords, OTP codes) separate from the public User collection. A dedicated entities-user-router is also introduced to give the User entity special handling (auth-gated reads/writes, restricted fields, role-based access) that mirrors production behavior.

Related Issue

None

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Other (please describe):

Changes Made

  • routes/auth-router.ts (new): Express router mounted at /api/apps/:appId/auth with three endpoints — POST /login, POST /register (generates a 6-digit OTP printed to the dev-server log), and POST /verify-otp (completes registration and issues a JWT)
  • routes/entities/entities-user-router.ts (new): Auth-gated CRUD router for the User entity; admins can list all users, regular users only see themselves; restricted fields (full_name, email, role) cannot be updated via the entities API, matching production behavior
  • db/entity-queries.ts (new): Extracted queryEntity helper supporting sort, limit, skip, fields, and q (JSON query) parameters — shared by the entity router and user router
  • db/database.ts: Added PRIVATE_USER_COLLECTION ($user) for storing passwords and OTP codes out of reach of public API clients
  • dev-server/main.ts: Registered the new authRouter and wired in the entities-user-router via the entity routes
  • package.json / bun.lock: Moved jsonwebtoken + @types/jsonwebtoken from the root workspace to packages/cli (where they are actually used); added qs for typed query-string parsing
  • tests/cli/dev-auth.spec.ts (new): Integration test covering the full register → OTP verify → login flow
  • Version bump: 0.0.470.0.50

Testing

  • I have tested these changes locally
  • I have added/updated tests as needed
  • All tests pass (npm test)

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • My changes generate no new warnings
  • I have updated docs/ (AGENTS.md) if I made architectural changes

Additional Notes

The OTP code is intentionally printed to the dev-server log (via devLogger) rather than sent by email, since local development has no email delivery. The JWT is signed with the hard-coded constant LOCAL_DEV_SECRET — this is intentional and safe for local-only use. Auth routes that involve OAuth redirects (/api/apps/auth/…) are still redirected to base44.app via the existing proxy redirect middleware.


🤖 Generated by Claude | 2026-04-14 08:44 UTC | 3ca36bb

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 12, 2026

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/cli@0.0.50-pr.475.3ca36bb

Prefer not to change any import paths? Install using npm alias so your code still imports base44:

npm i "base44@npm:@base44-preview/cli@0.0.50-pr.475.3ca36bb"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "base44": "npm:@base44-preview/cli@0.0.50-pr.475.3ca36bb"
  }
}

Preview published to npm registry — try new features instantly!

@artemdemo artemdemo force-pushed the auth-and-stuff branch 2 times, most recently from f104342 to 795a527 Compare April 12, 2026 13:05
@base44 base44 deleted a comment from claude bot Apr 12, 2026
@artemdemo
Copy link
Copy Markdown
Contributor Author

@claude review

"engines": {
"node": ">=20.19.0"
}
"name": "base44",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

just formatting - replaced 4 spaces with 2

"scripts": {
"lint": "biome check packages/*/src packages/*/tests",
"lint:fix": "biome check --write packages/*/src packages/*/tests",
"typecheck": "bun --workspaces --if-present --sequential run typecheck",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This allows to run bun run typecheck from the root of the project

@base44 base44 deleted a comment from claude bot Apr 13, 2026
@artemdemo
Copy link
Copy Markdown
Contributor Author

@claude review

@base44 base44 deleted a comment from claude bot Apr 13, 2026
@base44 base44 deleted a comment from claude bot Apr 13, 2026
@base44 base44 deleted a comment from claude bot Apr 13, 2026
return Object.keys(projection).length > 0 ? projection : undefined;
}

export const queryEntity = async (
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved this logic from entities-router.ts‎
So I can share it.

@artemdemo artemdemo marked this pull request as ready for review April 13, 2026 12:48
@artemdemo artemdemo changed the title Auth and stuff Auth and registration for local dev Apr 13, 2026
Comment on lines +33 to +40
join(
t.getTempDir(),
"project",
"base44",
"functions",
"hello",
"index.ts",
),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No related to PR, fixing windows thingy

env: {
...globalThis.process.env,
FUNCTION_PATH: func.entryPath,
FUNCTION_PATH: pathToFileURL(func.entryPath).href,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No related to PR, fixing windows thingy

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.

1 participant