@base44-preview/cli 0.0.50-pr.475.145bd51 → 0.0.50-pr.475.6fca043

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
@@ -253321,7 +253321,9 @@ class Validator {
253321
253321
  }
253322
253322
 
253323
253323
  // src/cli/dev/dev-server/db/database.ts
253324
+ var PRIVATE_COLLECTION_PREFIX = "$";
253324
253325
  var USER_COLLECTION = "user";
253326
+ var PRIVATE_USER_COLLECTION = PRIVATE_COLLECTION_PREFIX + USER_COLLECTION;
253325
253327
 
253326
253328
  class Database {
253327
253329
  collections = new Map;
@@ -253343,6 +253345,7 @@ class Database {
253343
253345
  this.schemas.set(USER_COLLECTION, this.buildUserSchema(userEntity));
253344
253346
  const collection = new import_nedb.default;
253345
253347
  this.collections.set(USER_COLLECTION, collection);
253348
+ this.collections.set(PRIVATE_USER_COLLECTION, new import_nedb.default);
253346
253349
  const userInfo = await readAuth();
253347
253350
  const now = getNowISOTimestamp();
253348
253351
  await collection.insertAsync({
@@ -253384,7 +253387,9 @@ class Database {
253384
253387
  return this.collections.get(this.normalizeName(name2));
253385
253388
  }
253386
253389
  getCollectionNames() {
253387
- return Array.from(this.collections.keys());
253390
+ return Array.from(this.collections.keys()).filter((name2) => {
253391
+ return !name2.startsWith(PRIVATE_COLLECTION_PREFIX);
253392
+ });
253388
253393
  }
253389
253394
  dropAll() {
253390
253395
  for (const collection of this.collections.values()) {
@@ -253461,26 +253466,29 @@ var createJwtToken = (email3) => {
253461
253466
  expiresIn: "360d"
253462
253467
  });
253463
253468
  };
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
253469
  function createAuthRouter(db2, logger2) {
253472
253470
  const router = import_express2.Router({ mergeParams: true });
253473
- const userRegitrPendingMap = new Map;
253474
253471
  const parseBody = import_express2.json();
253475
253472
  router.post("/login", parseBody, async (req, res) => {
253476
- const { email: email3, password: _password } = req.body;
253473
+ const { email: email3, password } = req.body;
253477
253474
  const result = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: email3 });
253478
253475
  if (result) {
253479
- res.json({
253480
- access_token: createJwtToken(email3),
253481
- success: true,
253482
- user: {}
253483
- });
253476
+ const privateUserData = await db2.getCollection(PRIVATE_USER_COLLECTION)?.findOneAsync({ email: email3 });
253477
+ if (result.role === "admin" || privateUserData?.password === password) {
253478
+ res.json({
253479
+ access_token: createJwtToken(email3),
253480
+ success: true,
253481
+ user: {}
253482
+ });
253483
+ } else {
253484
+ res.status(400).json({
253485
+ detail: "Invalid email or password",
253486
+ error_type: "HTTPException",
253487
+ message: "Invalid email or password",
253488
+ request_id: null,
253489
+ traceback: ""
253490
+ });
253491
+ }
253484
253492
  return;
253485
253493
  }
253486
253494
  res.status(401).json({ error: "Unauthorized" });
@@ -253508,15 +253516,21 @@ function createAuthRouter(db2, logger2) {
253508
253516
  });
253509
253517
  return;
253510
253518
  }
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()
253519
+ const privateUserCollection = db2.getCollection(PRIVATE_USER_COLLECTION);
253520
+ const privateUserData = await privateUserCollection?.findOneAsync({
253521
+ email: email3
253519
253522
  });
253523
+ const otpCode = privateUserData ? privateUserData.otpCode : generateCode();
253524
+ const id2 = privateUserData ? privateUserData.id : nanoid3();
253525
+ if (!privateUserData) {
253526
+ await privateUserCollection?.insertAsync({
253527
+ id: id2,
253528
+ email: email3,
253529
+ otpCode,
253530
+ password,
253531
+ createdAt: +Date.now()
253532
+ });
253533
+ }
253520
253534
  logger2.log(theme.styles.info(`
253521
253535
  In order to complete registration use this verification code: ${otpCode}
253522
253536
  `));
@@ -253528,15 +253542,25 @@ In order to complete registration use this verification code: ${otpCode}
253528
253542
  });
253529
253543
  router.post("/verify-otp", parseBody, async (req, res) => {
253530
253544
  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) {
253545
+ const privateUserCollection = db2.getCollection(PRIVATE_USER_COLLECTION);
253546
+ const privateUserData = await privateUserCollection?.findOneAsync({
253547
+ email: email3
253548
+ });
253549
+ if (privateUserData && privateUserData.otpCode === otp_code) {
253550
+ if (+Date.now() - privateUserData.createdAt < 10 * 60 * 1000) {
253551
+ privateUserCollection?.updateAsync({
253552
+ email: email3
253553
+ }, {
253554
+ $set: {
253555
+ otpCode: undefined
253556
+ }
253557
+ });
253534
253558
  const collection = db2.getCollection(USER_COLLECTION);
253535
253559
  const now = getNowISOTimestamp();
253536
253560
  const nameFromEmailMatch = /^([^@]+)/.exec(email3);
253537
253561
  const fullName = nameFromEmailMatch ? nameFromEmailMatch[1] : email3;
253538
253562
  await collection?.insertAsync({
253539
- id: userData.id,
253563
+ id: privateUserData.id,
253540
253564
  email: email3,
253541
253565
  full_name: fullName,
253542
253566
  is_service: false,
@@ -253548,7 +253572,7 @@ In order to complete registration use this verification code: ${otpCode}
253548
253572
  updated_date: now
253549
253573
  });
253550
253574
  res.json({
253551
- id: userData.id,
253575
+ id: privateUserData.id,
253552
253576
  access_token: createJwtToken(email3),
253553
253577
  message: "Email verified successfully. You are now logged in.",
253554
253578
  success: true
@@ -260360,4 +260384,4 @@ export {
260360
260384
  CLIExitError
260361
260385
  };
260362
260386
 
260363
- //# debugId=7F65D5426750E8BD64756E2164756E21
260387
+ //# debugId=00A0741C1AAAE2DF64756E2164756E21