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