@base44-preview/cli 0.0.50-pr.475.6fca043 → 0.0.50-pr.475.7817b8d

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",
@@ -253094,9 +253096,13 @@ function createFunctionRouter(manager, logger2) {
253094
253096
  on: {
253095
253097
  proxyReq: (proxyReq, req) => {
253096
253098
  const xAppId = req.headers["x-app-id"];
253099
+ const authorization = req.headers.authorization;
253097
253100
  if (xAppId) {
253098
253101
  proxyReq.setHeader("Base44-App-Id", xAppId);
253099
253102
  }
253103
+ if (authorization) {
253104
+ proxyReq.setHeader("Base44-Service-Authorization", authorization);
253105
+ }
253100
253106
  proxyReq.setHeader("Base44-Api-Url", `${req.protocol}://${req.headers.host}`);
253101
253107
  },
253102
253108
  error: (err, _req, res) => {
@@ -253466,11 +253472,13 @@ var createJwtToken = (email3) => {
253466
253472
  expiresIn: "360d"
253467
253473
  });
253468
253474
  };
253475
+ var LoginBody = object({ email: email2(), password: string2() });
253476
+ var VerifyOtpBody = object({ email: email2(), otp_code: string2() });
253469
253477
  function createAuthRouter(db2, logger2) {
253470
253478
  const router = import_express2.Router({ mergeParams: true });
253471
253479
  const parseBody = import_express2.json();
253472
253480
  router.post("/login", parseBody, async (req, res) => {
253473
- const { email: email3, password } = req.body;
253481
+ const { email: email3, password } = LoginBody.parse(req.body);
253474
253482
  const result = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: email3 });
253475
253483
  if (result) {
253476
253484
  const privateUserData = await db2.getCollection(PRIVATE_USER_COLLECTION)?.findOneAsync({ email: email3 });
@@ -253494,7 +253502,7 @@ function createAuthRouter(db2, logger2) {
253494
253502
  res.status(401).json({ error: "Unauthorized" });
253495
253503
  });
253496
253504
  router.post("/register", parseBody, async (req, res) => {
253497
- const { email: email3, password } = req.body;
253505
+ const { email: email3, password } = LoginBody.parse(req.body);
253498
253506
  if ((password || "").length < 8) {
253499
253507
  res.status(400).json({
253500
253508
  detail: "Password must be at least 8 characters long",
@@ -253520,7 +253528,7 @@ function createAuthRouter(db2, logger2) {
253520
253528
  const privateUserData = await privateUserCollection?.findOneAsync({
253521
253529
  email: email3
253522
253530
  });
253523
- const otpCode = privateUserData ? privateUserData.otpCode : generateCode();
253531
+ const otpCode = generateCode();
253524
253532
  const id2 = privateUserData ? privateUserData.id : nanoid3();
253525
253533
  if (!privateUserData) {
253526
253534
  await privateUserCollection?.insertAsync({
@@ -253528,7 +253536,16 @@ function createAuthRouter(db2, logger2) {
253528
253536
  email: email3,
253529
253537
  otpCode,
253530
253538
  password,
253531
- createdAt: +Date.now()
253539
+ createdAt: Date.now()
253540
+ });
253541
+ } else {
253542
+ await privateUserCollection?.updateAsync({
253543
+ email: email3
253544
+ }, {
253545
+ $set: {
253546
+ otpCode,
253547
+ createdAt: Date.now()
253548
+ }
253532
253549
  });
253533
253550
  }
253534
253551
  logger2.log(theme.styles.info(`
@@ -253541,19 +253558,17 @@ In order to complete registration use this verification code: ${otpCode}
253541
253558
  });
253542
253559
  });
253543
253560
  router.post("/verify-otp", parseBody, async (req, res) => {
253544
- const { email: email3, otp_code } = req.body;
253561
+ const { email: email3, otp_code } = VerifyOtpBody.parse(req.body);
253545
253562
  const privateUserCollection = db2.getCollection(PRIVATE_USER_COLLECTION);
253546
253563
  const privateUserData = await privateUserCollection?.findOneAsync({
253547
253564
  email: email3
253548
253565
  });
253549
253566
  if (privateUserData && privateUserData.otpCode === otp_code) {
253550
253567
  if (+Date.now() - privateUserData.createdAt < 10 * 60 * 1000) {
253551
- privateUserCollection?.updateAsync({
253568
+ await privateUserCollection?.updateAsync({
253552
253569
  email: email3
253553
253570
  }, {
253554
- $set: {
253555
- otpCode: undefined
253556
- }
253571
+ $unset: { otpCode: true }
253557
253572
  });
253558
253573
  const collection = db2.getCollection(USER_COLLECTION);
253559
253574
  const now = getNowISOTimestamp();
@@ -260384,4 +260399,4 @@ export {
260384
260399
  CLIExitError
260385
260400
  };
260386
260401
 
260387
- //# debugId=00A0741C1AAAE2DF64756E2164756E21
260402
+ //# debugId=CB186C06DA18198C64756E2164756E21