- 收口 rust final closure checklist,推进页面/块系统/Mindmap/CLI/AI tools 到最终 cutover 状态 - 按 ai-frontend-simplification-plan-v1 接入 Hermes bridge,合并 AI 面板并清理旧前端编排残留 - 补充 harness 任务与进度记录,加入 CLI smoke 夹具/脚本,并修正文档页 bridge SSR 自请求回退逻辑
27 lines
705 B
TypeScript
27 lines
705 B
TypeScript
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);
|
|
}
|
|
|
|
const devUserId = readEnv("DEV_USER_ID");
|
|
if (isDevAuthEnabled() || devUserId) {
|
|
return devUserId ?? "dev-user";
|
|
}
|
|
|
|
throw new Error("未登录");
|
|
}
|