@base44-preview/cli 0.0.50-pr.475.b600821 → 0.0.50-pr.475.c453156
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 +47 -22
- package/dist/cli/index.js.map +4 -4
- package/package.json +1 -1
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,16 +253466,17 @@ var createJwtToken = (email3) => {
|
|
|
253461
253466
|
expiresIn: "360d"
|
|
253462
253467
|
});
|
|
253463
253468
|
};
|
|
253469
|
+
var LoginBody = object({ email: email2(), password: string2() });
|
|
253470
|
+
var VerifyOtpBody = object({ email: email2(), otp_code: string2() });
|
|
253464
253471
|
function createAuthRouter(db2, logger2) {
|
|
253465
253472
|
const router = import_express2.Router({ mergeParams: true });
|
|
253466
|
-
const userRegistrPendingMap = new Map;
|
|
253467
253473
|
const parseBody = import_express2.json();
|
|
253468
253474
|
router.post("/login", parseBody, async (req, res) => {
|
|
253469
|
-
const { email: email3, password } = req.body;
|
|
253475
|
+
const { email: email3, password } = LoginBody.parse(req.body);
|
|
253470
253476
|
const result = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: email3 });
|
|
253471
253477
|
if (result) {
|
|
253472
|
-
const
|
|
253473
|
-
if (result.role === "admin" ||
|
|
253478
|
+
const privateUserData = await db2.getCollection(PRIVATE_USER_COLLECTION)?.findOneAsync({ email: email3 });
|
|
253479
|
+
if (result.role === "admin" || privateUserData?.password === password) {
|
|
253474
253480
|
res.json({
|
|
253475
253481
|
access_token: createJwtToken(email3),
|
|
253476
253482
|
success: true,
|
|
@@ -253490,7 +253496,7 @@ function createAuthRouter(db2, logger2) {
|
|
|
253490
253496
|
res.status(401).json({ error: "Unauthorized" });
|
|
253491
253497
|
});
|
|
253492
253498
|
router.post("/register", parseBody, async (req, res) => {
|
|
253493
|
-
const { email: email3, password } = req.body;
|
|
253499
|
+
const { email: email3, password } = LoginBody.parse(req.body);
|
|
253494
253500
|
if ((password || "").length < 8) {
|
|
253495
253501
|
res.status(400).json({
|
|
253496
253502
|
detail: "Password must be at least 8 characters long",
|
|
@@ -253512,15 +253518,27 @@ function createAuthRouter(db2, logger2) {
|
|
|
253512
253518
|
});
|
|
253513
253519
|
return;
|
|
253514
253520
|
}
|
|
253515
|
-
const
|
|
253516
|
-
const
|
|
253517
|
-
|
|
253518
|
-
id: id2,
|
|
253519
|
-
email: email3,
|
|
253520
|
-
otpCode,
|
|
253521
|
-
password,
|
|
253522
|
-
createdAt: +Date.now()
|
|
253521
|
+
const privateUserCollection = db2.getCollection(PRIVATE_USER_COLLECTION);
|
|
253522
|
+
const privateUserData = await privateUserCollection?.findOneAsync({
|
|
253523
|
+
email: email3
|
|
253523
253524
|
});
|
|
253525
|
+
const otpCode = generateCode();
|
|
253526
|
+
const id2 = privateUserData ? privateUserData.id : nanoid3();
|
|
253527
|
+
if (!privateUserData) {
|
|
253528
|
+
await privateUserCollection?.insertAsync({
|
|
253529
|
+
id: id2,
|
|
253530
|
+
email: email3,
|
|
253531
|
+
otpCode,
|
|
253532
|
+
password,
|
|
253533
|
+
createdAt: Date.now()
|
|
253534
|
+
});
|
|
253535
|
+
} else {
|
|
253536
|
+
await privateUserCollection?.updateAsync({
|
|
253537
|
+
email: email3
|
|
253538
|
+
}, {
|
|
253539
|
+
$set: { otpCode }
|
|
253540
|
+
});
|
|
253541
|
+
}
|
|
253524
253542
|
logger2.log(theme.styles.info(`
|
|
253525
253543
|
In order to complete registration use this verification code: ${otpCode}
|
|
253526
253544
|
`));
|
|
@@ -253531,17 +253549,24 @@ In order to complete registration use this verification code: ${otpCode}
|
|
|
253531
253549
|
});
|
|
253532
253550
|
});
|
|
253533
253551
|
router.post("/verify-otp", parseBody, async (req, res) => {
|
|
253534
|
-
const { email: email3, otp_code } = req.body;
|
|
253535
|
-
const
|
|
253536
|
-
|
|
253537
|
-
|
|
253538
|
-
|
|
253552
|
+
const { email: email3, otp_code } = VerifyOtpBody.parse(req.body);
|
|
253553
|
+
const privateUserCollection = db2.getCollection(PRIVATE_USER_COLLECTION);
|
|
253554
|
+
const privateUserData = await privateUserCollection?.findOneAsync({
|
|
253555
|
+
email: email3
|
|
253556
|
+
});
|
|
253557
|
+
if (privateUserData && privateUserData.otpCode === otp_code) {
|
|
253558
|
+
if (+Date.now() - privateUserData.createdAt < 10 * 60 * 1000) {
|
|
253559
|
+
await privateUserCollection?.updateAsync({
|
|
253560
|
+
email: email3
|
|
253561
|
+
}, {
|
|
253562
|
+
$unset: { otpCode: true }
|
|
253563
|
+
});
|
|
253539
253564
|
const collection = db2.getCollection(USER_COLLECTION);
|
|
253540
253565
|
const now = getNowISOTimestamp();
|
|
253541
253566
|
const nameFromEmailMatch = /^([^@]+)/.exec(email3);
|
|
253542
253567
|
const fullName = nameFromEmailMatch ? nameFromEmailMatch[1] : email3;
|
|
253543
253568
|
await collection?.insertAsync({
|
|
253544
|
-
id:
|
|
253569
|
+
id: privateUserData.id,
|
|
253545
253570
|
email: email3,
|
|
253546
253571
|
full_name: fullName,
|
|
253547
253572
|
is_service: false,
|
|
@@ -253553,7 +253578,7 @@ In order to complete registration use this verification code: ${otpCode}
|
|
|
253553
253578
|
updated_date: now
|
|
253554
253579
|
});
|
|
253555
253580
|
res.json({
|
|
253556
|
-
id:
|
|
253581
|
+
id: privateUserData.id,
|
|
253557
253582
|
access_token: createJwtToken(email3),
|
|
253558
253583
|
message: "Email verified successfully. You are now logged in.",
|
|
253559
253584
|
success: true
|
|
@@ -260365,4 +260390,4 @@ export {
|
|
|
260365
260390
|
CLIExitError
|
|
260366
260391
|
};
|
|
260367
260392
|
|
|
260368
|
-
//# debugId=
|
|
260393
|
+
//# debugId=FD0C9C6814D0182C64756E2164756E21
|