0.6 rust重构01

This commit is contained in:
lix-2026
2026-04-14 13:22:29 +08:00
parent 71fb1aee7e
commit 84a8454fa9
401 changed files with 5841 additions and 1512 deletions
+25
View File
@@ -0,0 +1,25 @@
import { getAuthUserId } from "@convex-dev/auth/server";
function readEnv(key: string): string | undefined {
const raw = process.env[key];
if (!raw) return undefined;
const trimmed = raw.trim();
return trimmed ? trimmed : undefined;
}
function isDevAuthEnabled(): boolean {
return readEnv("MNOTE_DEV_AUTH") === "1" || readEnv("NEXT_PUBLIC_MNOTE_DEV_AUTH") === "1";
}
export async function requireUserId(ctx: any): Promise<string> {
const userId = await getAuthUserId(ctx);
if (userId !== null) {
return String(userId);
}
if (isDevAuthEnabled()) {
return readEnv("DEV_USER_ID") ?? "dev-user";
}
throw new Error("未登录");
}