fix(auth): unify Desktop and Web SQLite DB path and fix browser autofill crash on Input/AuthGate
This commit is contained in:
@@ -70,6 +70,15 @@ export function registerAdminRoutes(app: FastifyInstance): void {
|
||||
|
||||
const fields: string[] = [];
|
||||
const values: unknown[] = [];
|
||||
if (body.email !== undefined) {
|
||||
const cleanEmail = body.email.trim().toLowerCase();
|
||||
const taken = db
|
||||
.prepare("SELECT id FROM users WHERE LOWER(email) = ? AND id != ?")
|
||||
.get(cleanEmail, id);
|
||||
if (taken) throw instance.httpErrors.create(409, { error: "email_taken" });
|
||||
fields.push("email = ?");
|
||||
values.push(cleanEmail);
|
||||
}
|
||||
if (body.displayName !== undefined) {
|
||||
fields.push("display_name = ?");
|
||||
values.push(body.displayName);
|
||||
@@ -189,6 +198,7 @@ const userCreate = z.object({
|
||||
});
|
||||
|
||||
const userPatch = z.object({
|
||||
email: z.string().trim().toLowerCase().email().optional(),
|
||||
role: z.enum(["admin", "author"]).optional(),
|
||||
disabled: z.boolean().optional(),
|
||||
displayName: z.string().min(1).max(80).optional(),
|
||||
|
||||
+18
-7
@@ -2,8 +2,12 @@
|
||||
* Environment-driven server configuration.
|
||||
*
|
||||
* All values are read from `process.env` at import time with sensible
|
||||
* defaults so the server boots with zero configuration for local dev.
|
||||
* defaults so the server and desktop app share the same canonical user data
|
||||
* directory (`~/.local/share/pubscript/pubscript.sqlite`).
|
||||
*/
|
||||
import { existsSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
function env(key: string, fallback: string): string {
|
||||
const value = process.env[key];
|
||||
@@ -17,6 +21,18 @@ function envInt(key: string, fallback: number): number {
|
||||
return Number.isFinite(n) ? n : fallback;
|
||||
}
|
||||
|
||||
function defaultDatabasePath(): string {
|
||||
if (process.env.VITEST || process.env.NODE_ENV === "test") {
|
||||
return ":memory:";
|
||||
}
|
||||
// In Docker container runtime, use /app/data/pubscript.sqlite if /app/data exists
|
||||
if (existsSync("/app/data")) {
|
||||
return "/app/data/pubscript.sqlite";
|
||||
}
|
||||
const dataHome = process.env.XDG_DATA_HOME || join(homedir(), ".local", "share");
|
||||
return join(dataHome, "pubscript", "pubscript.sqlite");
|
||||
}
|
||||
|
||||
export interface ServerConfig {
|
||||
/** Path to the SQLite database file. */
|
||||
dbPath: string;
|
||||
@@ -33,12 +49,7 @@ export interface ServerConfig {
|
||||
}
|
||||
|
||||
export const config: ServerConfig = {
|
||||
dbPath: env(
|
||||
"PUBSCRIPT_DB",
|
||||
process.env.VITEST || process.env.NODE_ENV === "test"
|
||||
? ":memory:"
|
||||
: "./data/pubscript.sqlite",
|
||||
),
|
||||
dbPath: env("PUBSCRIPT_DB", defaultDatabasePath()),
|
||||
port: envInt("PORT", 8080),
|
||||
origin: env("PUBSCRIPT_ORIGIN", "http://localhost:5173"),
|
||||
adminEmail: env("PUBSCRIPT_ADMIN_EMAIL", "admin@pubscript.local"),
|
||||
|
||||
Reference in New Issue
Block a user