@base44-preview/cli 0.0.50-pr.475.145bd51 → 0.0.50-pr.475.235c44c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/index.js CHANGED
@@ -243211,6 +243211,7 @@ var package_default = {
243211
243211
  "@types/ejs": "^3.1.5",
243212
243212
  "@types/express": "^5.0.6",
243213
243213
  "@types/json-schema": "^7.0.15",
243214
+ "@types/jsonwebtoken": "^9.0.10",
243214
243215
  "@types/lodash": "^4.17.24",
243215
243216
  "@types/multer": "^2.0.0",
243216
243217
  "@types/node": "^22.10.5",
@@ -243229,6 +243230,7 @@ var package_default = {
243229
243230
  globby: "^16.1.0",
243230
243231
  "http-proxy-middleware": "^3.0.5",
243231
243232
  "json-schema-to-typescript": "^15.0.4",
243233
+ jsonwebtoken: "^9.0.3",
243232
243234
  json5: "^2.2.3",
243233
243235
  ky: "^1.14.2",
243234
243236
  lodash: "^4.17.23",
@@ -253321,7 +253323,9 @@ class Validator {
253321
253323
  }
253322
253324
 
253323
253325
  // src/cli/dev/dev-server/db/database.ts
253326
+ var PRIVATE_COLLECTION_PREFIX = "$";
253324
253327
  var USER_COLLECTION = "user";
253328
+ var PRIVATE_USER_COLLECTION = PRIVATE_COLLECTION_PREFIX + USER_COLLECTION;
253325
253329
 
253326
253330
  class Database {
253327
253331
  collections = new Map;
@@ -253343,6 +253347,7 @@ class Database {
253343
253347
  this.schemas.set(USER_COLLECTION, this.buildUserSchema(userEntity));
253344
253348
  const collection = new import_nedb.default;
253345
253349
  this.collections.set(USER_COLLECTION, collection);
253350
+ this.collections.set(PRIVATE_USER_COLLECTION, new import_nedb.default);
253346
253351
  const userInfo = await readAuth();
253347
253352
  const now = getNowISOTimestamp();
253348
253353
  await collection.insertAsync({
@@ -253384,7 +253389,9 @@ class Database {
253384
253389
  return this.collections.get(this.normalizeName(name2));
253385
253390
  }
253386
253391
  getCollectionNames() {
253387
- return Array.from(this.collections.keys());
253392
+ return Array.from(this.collections.keys()).filter((name2) => {
253393
+ return !name2.startsWith(PRIVATE_COLLECTION_PREFIX);
253394
+ });
253388
253395
  }
253389
253396
  dropAll() {
253390
253397
  for (const collection of this.collections.values()) {
@@ -253461,32 +253468,37 @@ var createJwtToken = (email3) => {
253461
253468
  expiresIn: "360d"
253462
253469
  });
253463
253470
  };
253464
- var UserRegiterSchema = object({
253465
- id: string2(),
253466
- email: email2(),
253467
- otpCode: string2().length(6),
253468
- password: string2().min(8),
253469
- createdAt: number2().min(1)
253470
- });
253471
+ var LoginBody = object({ email: email2(), password: string2() });
253472
+ var VerifyOtpBody = object({ email: email2(), otp_code: string2() });
253471
253473
  function createAuthRouter(db2, logger2) {
253472
253474
  const router = import_express2.Router({ mergeParams: true });
253473
- const userRegitrPendingMap = new Map;
253474
253475
  const parseBody = import_express2.json();
253475
253476
  router.post("/login", parseBody, async (req, res) => {
253476
- const { email: email3, password: _password } = req.body;
253477
+ const { email: email3, password } = LoginBody.parse(req.body);
253477
253478
  const result = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: email3 });
253478
253479
  if (result) {
253479
- res.json({
253480
- access_token: createJwtToken(email3),
253481
- success: true,
253482
- user: {}
253483
- });
253480
+ const privateUserData = await db2.getCollection(PRIVATE_USER_COLLECTION)?.findOneAsync({ email: email3 });
253481
+ if (result.role === "admin" || privateUserData?.password === password) {
253482
+ res.json({
253483
+ access_token: createJwtToken(email3),
253484
+ success: true,
253485
+ user: {}
253486
+ });
253487
+ } else {
253488
+ res.status(400).json({
253489
+ detail: "Invalid email or password",
253490
+ error_type: "HTTPException",
253491
+ message: "Invalid email or password",
253492
+ request_id: null,
253493
+ traceback: ""
253494
+ });
253495
+ }
253484
253496
  return;
253485
253497
  }
253486
253498
  res.status(401).json({ error: "Unauthorized" });
253487
253499
  });
253488
253500
  router.post("/register", parseBody, async (req, res) => {
253489
- const { email: email3, password } = req.body;
253501
+ const { email: email3, password } = LoginBody.parse(req.body);
253490
253502
  if ((password || "").length < 8) {
253491
253503
  res.status(400).json({
253492
253504
  detail: "Password must be at least 8 characters long",
@@ -253508,15 +253520,30 @@ function createAuthRouter(db2, logger2) {
253508
253520
  });
253509
253521
  return;
253510
253522
  }
253511
- const otpCode = generateCode();
253512
- const id2 = nanoid3();
253513
- userRegitrPendingMap.set(email3, {
253514
- id: id2,
253515
- email: email3,
253516
- otpCode,
253517
- password,
253518
- createdAt: +Date.now()
253523
+ const privateUserCollection = db2.getCollection(PRIVATE_USER_COLLECTION);
253524
+ const privateUserData = await privateUserCollection?.findOneAsync({
253525
+ email: email3
253519
253526
  });
253527
+ const otpCode = generateCode();
253528
+ const id2 = privateUserData ? privateUserData.id : nanoid3();
253529
+ if (!privateUserData) {
253530
+ await privateUserCollection?.insertAsync({
253531
+ id: id2,
253532
+ email: email3,
253533
+ otpCode,
253534
+ password,
253535
+ createdAt: Date.now()
253536
+ });
253537
+ } else {
253538
+ await privateUserCollection?.updateAsync({
253539
+ email: email3
253540
+ }, {
253541
+ $set: {
253542
+ otpCode,
253543
+ createdAt: Date.now()
253544
+ }
253545
+ });
253546
+ }
253520
253547
  logger2.log(theme.styles.info(`
253521
253548
  In order to complete registration use this verification code: ${otpCode}
253522
253549
  `));
@@ -253527,16 +253554,24 @@ In order to complete registration use this verification code: ${otpCode}
253527
253554
  });
253528
253555
  });
253529
253556
  router.post("/verify-otp", parseBody, async (req, res) => {
253530
- const { email: email3, otp_code } = req.body;
253531
- const userData = userRegitrPendingMap.get(email3);
253532
- if (userData && userData.otpCode === otp_code) {
253533
- if (+Date.now() - userData.createdAt < 10 * 60 * 1000) {
253557
+ const { email: email3, otp_code } = VerifyOtpBody.parse(req.body);
253558
+ const privateUserCollection = db2.getCollection(PRIVATE_USER_COLLECTION);
253559
+ const privateUserData = await privateUserCollection?.findOneAsync({
253560
+ email: email3
253561
+ });
253562
+ if (privateUserData && privateUserData.otpCode === otp_code) {
253563
+ if (+Date.now() - privateUserData.createdAt < 10 * 60 * 1000) {
253564
+ await privateUserCollection?.updateAsync({
253565
+ email: email3
253566
+ }, {
253567
+ $unset: { otpCode: true }
253568
+ });
253534
253569
  const collection = db2.getCollection(USER_COLLECTION);
253535
253570
  const now = getNowISOTimestamp();
253536
253571
  const nameFromEmailMatch = /^([^@]+)/.exec(email3);
253537
253572
  const fullName = nameFromEmailMatch ? nameFromEmailMatch[1] : email3;
253538
253573
  await collection?.insertAsync({
253539
- id: userData.id,
253574
+ id: privateUserData.id,
253540
253575
  email: email3,
253541
253576
  full_name: fullName,
253542
253577
  is_service: false,
@@ -253548,7 +253583,7 @@ In order to complete registration use this verification code: ${otpCode}
253548
253583
  updated_date: now
253549
253584
  });
253550
253585
  res.json({
253551
- id: userData.id,
253586
+ id: privateUserData.id,
253552
253587
  access_token: createJwtToken(email3),
253553
253588
  message: "Email verified successfully. You are now logged in.",
253554
253589
  success: true
@@ -260360,4 +260395,4 @@ export {
260360
260395
  CLIExitError
260361
260396
  };
260362
260397
 
260363
- //# debugId=7F65D5426750E8BD64756E2164756E21
260398
+ //# debugId=8BC0D7129D49BDE164756E2164756E21