@base44-preview/cli 0.0.50-pr.475.a662eb9 → 0.0.50-pr.475.b981e6a

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",
@@ -253466,11 +253468,13 @@ var createJwtToken = (email3) => {
253466
253468
  expiresIn: "360d"
253467
253469
  });
253468
253470
  };
253471
+ var LoginBody = object({ email: email2(), password: string2() });
253472
+ var VerifyOtpBody = object({ email: email2(), otp_code: string2() });
253469
253473
  function createAuthRouter(db2, logger2) {
253470
253474
  const router = import_express2.Router({ mergeParams: true });
253471
253475
  const parseBody = import_express2.json();
253472
253476
  router.post("/login", parseBody, async (req, res) => {
253473
- const { email: email3, password } = req.body;
253477
+ const { email: email3, password } = LoginBody.parse(req.body);
253474
253478
  const result = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: email3 });
253475
253479
  if (result) {
253476
253480
  const privateUserData = await db2.getCollection(PRIVATE_USER_COLLECTION)?.findOneAsync({ email: email3 });
@@ -253494,7 +253498,7 @@ function createAuthRouter(db2, logger2) {
253494
253498
  res.status(401).json({ error: "Unauthorized" });
253495
253499
  });
253496
253500
  router.post("/register", parseBody, async (req, res) => {
253497
- const { email: email3, password } = req.body;
253501
+ const { email: email3, password } = LoginBody.parse(req.body);
253498
253502
  if ((password || "").length < 8) {
253499
253503
  res.status(400).json({
253500
253504
  detail: "Password must be at least 8 characters long",
@@ -253520,7 +253524,7 @@ function createAuthRouter(db2, logger2) {
253520
253524
  const privateUserData = await privateUserCollection?.findOneAsync({
253521
253525
  email: email3
253522
253526
  });
253523
- const otpCode = privateUserData ? privateUserData.otpCode : generateCode();
253527
+ const otpCode = generateCode();
253524
253528
  const id2 = privateUserData ? privateUserData.id : nanoid3();
253525
253529
  if (!privateUserData) {
253526
253530
  await privateUserCollection?.insertAsync({
@@ -253528,7 +253532,16 @@ function createAuthRouter(db2, logger2) {
253528
253532
  email: email3,
253529
253533
  otpCode,
253530
253534
  password,
253531
- createdAt: +Date.now()
253535
+ createdAt: Date.now()
253536
+ });
253537
+ } else {
253538
+ await privateUserCollection?.updateAsync({
253539
+ email: email3
253540
+ }, {
253541
+ $set: {
253542
+ otpCode,
253543
+ createdAt: Date.now()
253544
+ }
253532
253545
  });
253533
253546
  }
253534
253547
  logger2.log(theme.styles.info(`
@@ -253541,19 +253554,17 @@ In order to complete registration use this verification code: ${otpCode}
253541
253554
  });
253542
253555
  });
253543
253556
  router.post("/verify-otp", parseBody, async (req, res) => {
253544
- const { email: email3, otp_code } = req.body;
253557
+ const { email: email3, otp_code } = VerifyOtpBody.parse(req.body);
253545
253558
  const privateUserCollection = db2.getCollection(PRIVATE_USER_COLLECTION);
253546
253559
  const privateUserData = await privateUserCollection?.findOneAsync({
253547
253560
  email: email3
253548
253561
  });
253549
253562
  if (privateUserData && privateUserData.otpCode === otp_code) {
253550
253563
  if (+Date.now() - privateUserData.createdAt < 10 * 60 * 1000) {
253551
- privateUserCollection?.updateAsync({
253564
+ await privateUserCollection?.updateAsync({
253552
253565
  email: email3
253553
253566
  }, {
253554
- $set: {
253555
- otpCode: undefined
253556
- }
253567
+ $unset: { otpCode: true }
253557
253568
  });
253558
253569
  const collection = db2.getCollection(USER_COLLECTION);
253559
253570
  const now = getNowISOTimestamp();
@@ -260384,4 +260395,4 @@ export {
260384
260395
  CLIExitError
260385
260396
  };
260386
260397
 
260387
- //# debugId=00A0741C1AAAE2DF64756E2164756E21
260398
+ //# debugId=8BC0D7129D49BDE164756E2164756E21