0.6 rust重构01
This commit is contained in:
@@ -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("未登录");
|
||||
}
|
||||
Reference in New Issue
Block a user