Fix encryption not loading
This commit is contained in:
@@ -588,9 +588,9 @@ async function handlePostInitFileEncryption() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export a promise that resolves when database is fully initialized
|
// Database initialization function - called explicitly, not at module import time
|
||||||
export const databaseReady = initializeCompleteDatabase()
|
async function initializeDatabase(): Promise<void> {
|
||||||
.then(async () => {
|
await initializeCompleteDatabase();
|
||||||
await handlePostInitFileEncryption();
|
await handlePostInitFileEncryption();
|
||||||
|
|
||||||
databaseLogger.success("Database connection established", {
|
databaseLogger.success("Database connection established", {
|
||||||
@@ -600,13 +600,10 @@ export const databaseReady = initializeCompleteDatabase()
|
|||||||
enableFileEncryption &&
|
enableFileEncryption &&
|
||||||
DatabaseFileEncryption.isEncryptedDatabaseFile(encryptedDbPath),
|
DatabaseFileEncryption.isEncryptedDatabaseFile(encryptedDbPath),
|
||||||
});
|
});
|
||||||
})
|
}
|
||||||
.catch((error) => {
|
|
||||||
databaseLogger.error("Failed to initialize database", error, {
|
// Export the initialization function instead of auto-starting
|
||||||
operation: "db_init",
|
export { initializeDatabase };
|
||||||
});
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Cleanup function for database and temporary files
|
// Cleanup function for database and temporary files
|
||||||
async function cleanupDatabase() {
|
async function cleanupDatabase() {
|
||||||
@@ -693,7 +690,7 @@ let db: ReturnType<typeof drizzle<typeof schema>>;
|
|||||||
// Export database connection getter function to avoid undefined access
|
// Export database connection getter function to avoid undefined access
|
||||||
export function getDb(): ReturnType<typeof drizzle<typeof schema>> {
|
export function getDb(): ReturnType<typeof drizzle<typeof schema>> {
|
||||||
if (!db) {
|
if (!db) {
|
||||||
throw new Error("Database not initialized. Ensure databaseReady promise is awaited before accessing db.");
|
throw new Error("Database not initialized. Ensure initializeDatabase() is called before accessing db.");
|
||||||
}
|
}
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
@@ -701,7 +698,7 @@ export function getDb(): ReturnType<typeof drizzle<typeof schema>> {
|
|||||||
// Export raw SQLite instance for migrations
|
// Export raw SQLite instance for migrations
|
||||||
export function getSqlite(): Database.Database {
|
export function getSqlite(): Database.Database {
|
||||||
if (!sqlite) {
|
if (!sqlite) {
|
||||||
throw new Error("SQLite not initialized. Ensure databaseReady promise is awaited before accessing sqlite.");
|
throw new Error("SQLite not initialized. Ensure initializeDatabase() is called before accessing sqlite.");
|
||||||
}
|
}
|
||||||
return sqlite;
|
return sqlite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ import { systemLogger, versionLogger } from "./utils/logger.js";
|
|||||||
operation: "database_init"
|
operation: "database_init"
|
||||||
});
|
});
|
||||||
const dbModule = await import("./database/db/index.js");
|
const dbModule = await import("./database/db/index.js");
|
||||||
await dbModule.databaseReady;
|
await dbModule.initializeDatabase();
|
||||||
systemLogger.success("Database initialized successfully", {
|
systemLogger.success("Database initialized successfully", {
|
||||||
operation: "database_init_complete"
|
operation: "database_init_complete"
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -97,10 +97,9 @@ class AuthManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Import database connection - need to access raw SQLite for migration
|
// Import database connection - need to access raw SQLite for migration
|
||||||
const { getSqlite, saveMemoryDatabaseToFile, databaseReady } = await import("../database/db/index.js");
|
const { getSqlite, saveMemoryDatabaseToFile } = await import("../database/db/index.js");
|
||||||
|
|
||||||
// Ensure database is fully initialized before accessing SQLite
|
// Database should already be initialized by starter.ts, but ensure we can access it
|
||||||
await databaseReady;
|
|
||||||
const sqlite = getSqlite();
|
const sqlite = getSqlite();
|
||||||
|
|
||||||
// Perform the migration
|
// Perform the migration
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ export function HomepageAuth({
|
|||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [internalLoggedIn, setInternalLoggedIn] = useState(false);
|
const [internalLoggedIn, setInternalLoggedIn] = useState(false);
|
||||||
const [firstUser, setFirstUser] = useState(false);
|
const [firstUser, setFirstUser] = useState(false);
|
||||||
|
const [firstUserToastShown, setFirstUserToastShown] = useState(false);
|
||||||
const [registrationAllowed, setRegistrationAllowed] = useState(true);
|
const [registrationAllowed, setRegistrationAllowed] = useState(true);
|
||||||
const [oidcConfigured, setOidcConfigured] = useState(false);
|
const [oidcConfigured, setOidcConfigured] = useState(false);
|
||||||
|
|
||||||
@@ -143,7 +144,10 @@ export function HomepageAuth({
|
|||||||
if (res.setup_required) {
|
if (res.setup_required) {
|
||||||
setFirstUser(true);
|
setFirstUser(true);
|
||||||
setTab("signup");
|
setTab("signup");
|
||||||
|
if (!firstUserToastShown) {
|
||||||
toast.info(t("auth.firstUserMessage"));
|
toast.info(t("auth.firstUserMessage"));
|
||||||
|
setFirstUserToastShown(true);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setFirstUser(false);
|
setFirstUser(false);
|
||||||
}
|
}
|
||||||
@@ -156,7 +160,7 @@ export function HomepageAuth({
|
|||||||
.finally(() => {
|
.finally(() => {
|
||||||
setDbHealthChecking(false);
|
setDbHealthChecking(false);
|
||||||
});
|
});
|
||||||
}, [setDbError, t]);
|
}, [setDbError, firstUserToastShown]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!registrationAllowed && !internalLoggedIn) {
|
if (!registrationAllowed && !internalLoggedIn) {
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ export function HomepageAuth({
|
|||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [internalLoggedIn, setInternalLoggedIn] = useState(false);
|
const [internalLoggedIn, setInternalLoggedIn] = useState(false);
|
||||||
const [firstUser, setFirstUser] = useState(false);
|
const [firstUser, setFirstUser] = useState(false);
|
||||||
|
const [firstUserToastShown, setFirstUserToastShown] = useState(false);
|
||||||
const [registrationAllowed, setRegistrationAllowed] = useState(true);
|
const [registrationAllowed, setRegistrationAllowed] = useState(true);
|
||||||
const [oidcConfigured, setOidcConfigured] = useState(false);
|
const [oidcConfigured, setOidcConfigured] = useState(false);
|
||||||
|
|
||||||
@@ -123,7 +124,10 @@ export function HomepageAuth({
|
|||||||
if (res.setup_required) {
|
if (res.setup_required) {
|
||||||
setFirstUser(true);
|
setFirstUser(true);
|
||||||
setTab("signup");
|
setTab("signup");
|
||||||
|
if (!firstUserToastShown) {
|
||||||
toast.info(t("auth.firstUserMessage"));
|
toast.info(t("auth.firstUserMessage"));
|
||||||
|
setFirstUserToastShown(true);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setFirstUser(false);
|
setFirstUser(false);
|
||||||
}
|
}
|
||||||
@@ -132,7 +136,7 @@ export function HomepageAuth({
|
|||||||
.catch(() => {
|
.catch(() => {
|
||||||
setDbError(t("errors.databaseConnection"));
|
setDbError(t("errors.databaseConnection"));
|
||||||
});
|
});
|
||||||
}, [setDbError, t]);
|
}, [setDbError, firstUserToastShown]);
|
||||||
|
|
||||||
async function handleSubmit(e: React.FormEvent) {
|
async function handleSubmit(e: React.FormEvent) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
Reference in New Issue
Block a user