refactor(login): added in a check for lastlogin and force reset password

this also includes passowrd for non alpla users will deal with them later
This commit is contained in:
2025-10-21 20:24:55 -05:00
parent eb3fa4dd52
commit 17e13d4604
6 changed files with 10924 additions and 10540 deletions

View File

@@ -18,7 +18,7 @@ import { settings } from "./src/pkg/db/schema/settings.js";
import { createLogger } from "./src/pkg/logger/logger.js";
import { v1Listener } from "./src/pkg/logger/v1Listener.js";
import { apiHitMiddleware } from "./src/pkg/middleware/apiHits.js";
import { initializeProdPool } from "./src/pkg/prodSql/prodSqlConnect.js";
import { initializeProdPool, pool } from "./src/pkg/prodSql/prodSqlConnect.js";
import { validateEnv } from "./src/pkg/utils/envValidator.js";
import { sendNotify } from "./src/pkg/utils/notify.js";
import { returnFunc } from "./src/pkg/utils/return.js";
@@ -89,7 +89,10 @@ const main = async () => {
const allowedOrigins = [
/^https?:\/\/localhost:(5173|5500|4200|3000|4000)$/, // all the allowed backend ports
/^http?:\/\/localhost:(5173|5500|4200|3000|4000)$/,
/^https?:\/\/.*\.alpla\.net$/,
"http://localhost:4173",
"http://localhost:4200",
env.BETTER_AUTH_URL, // prod
];
@@ -120,6 +123,8 @@ const main = async () => {
},
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
credentials: true,
exposedHeaders: ["set-cookie"],
allowedHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
}),
);
@@ -130,6 +135,14 @@ const main = async () => {
express.static(join(__dirname, "../frontend/dist")),
);
app.get(basePath + "/app/*splat", (req, res) => {
res.sendFile(join(__dirname, "../frontend/dist/index.html"));
});
app.get(basePath + "/d/*splat", (req, res) => {
res.sendFile(join(__dirname, "../lstDocs/build/index.html"));
});
// server setup
const server = createServer(app);
@@ -188,6 +201,30 @@ const main = async () => {
//process.exit(1);
});
process.on("SIGINT", async () => {
console.log("\nGracefully shutting down...");
try {
await pool.close();
console.log("Closed SQL connection.");
} catch (err) {
console.error("Error closing SQL connection:", err);
} finally {
process.exit(0);
}
});
// Also handle other termination signals (optional)
process.on("SIGTERM", async () => {
console.log("SIGTERM received. Closing SQL connection...");
try {
await pool.close();
} catch (err) {
console.error(err);
} finally {
process.exit(0);
}
});
// setInterval(() => {
// const used = process.memoryUsage();
// console.log(