feat: add local auth billing and usage management
This commit is contained in:
1 parent
f642b5e71f
commit
196fdde83f
119 files changed
+15695
-2650
No files matched your search
@@ -1,13 +1,4 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { AuthLoginPanel } from "@/components/auth-login-panel";
|
||||
import { getAuthRuntimeConfig, safeNextPath } from "@/lib/auth/config";
|
||||
import { getOptionalAuthSession } from "@/lib/server/auth/current-user";
|
||||
|
||||
const errorMessages: Record<string, string> = {
|
||||
auth_not_configured: "认证配置不完整,请先在服务器环境变量中配置 SSO。",
|
||||
callback_failed: "登录回调处理失败,请重新登录。",
|
||||
state_invalid: "登录状态已失效,请重新登录。"
|
||||
};
|
||||
|
||||
export default async function AdminLoginPage({
|
||||
searchParams
|
||||
@@ -15,33 +6,6 @@ export default async function AdminLoginPage({
|
||||
searchParams?: Promise<Record<string, string | string[] | undefined>>;
|
||||
}) {
|
||||
const params = await searchParams;
|
||||
const next = safeNextPath(singleParam(params?.next));
|
||||
const session = await getOptionalAuthSession();
|
||||
if (session) redirect(next);
|
||||
|
||||
const config = getAuthRuntimeConfig({ clientMode: "admin" });
|
||||
const errorCode = singleParam(params?.error);
|
||||
const message = errorCode ? errorMessages[errorCode] || "登录失败,请重新登录。" : null;
|
||||
|
||||
return (
|
||||
<AuthLoginPanel
|
||||
next={next}
|
||||
configured={config.configured}
|
||||
message={message}
|
||||
missing={!config.configured && config.required ? config.missing : []}
|
||||
title="管理员登录"
|
||||
submitLabel="管理员登录"
|
||||
authMode="admin"
|
||||
alternateHref={loginHref("/auth/login", next)}
|
||||
alternateLabel="普通账号登录"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function singleParam(value: string | string[] | undefined): string | undefined {
|
||||
return Array.isArray(value) ? value[0] : value;
|
||||
}
|
||||
|
||||
function loginHref(path: string, next: string): string {
|
||||
return `${path}?next=${encodeURIComponent(next)}`;
|
||||
const next = Array.isArray(params?.next) ? params?.next[0] : params?.next;
|
||||
redirect(next ? `/auth/login?next=${encodeURIComponent(next)}` : "/auth/login");
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import { getAuthRuntimeConfig, safeNextPath } from "@/lib/auth/config";
|
||||
import { getOptionalAuthSession } from "@/lib/server/auth/current-user";
|
||||
|
||||
const errorMessages: Record<string, string> = {
|
||||
auth_not_configured: "认证配置不完整,请先在服务器环境变量中配置 SSO。",
|
||||
callback_failed: "登录回调处理失败,请重新登录。",
|
||||
auth_not_configured: "账号认证配置不完整,请联系管理员。",
|
||||
callback_failed: "登录失败,请重新登录。",
|
||||
state_invalid: "登录状态已失效,请重新登录。"
|
||||
};
|
||||
|
||||
@@ -29,8 +29,6 @@ export default async function LoginPage({
|
||||
configured={config.configured}
|
||||
message={message}
|
||||
missing={!config.configured && config.required ? config.missing : []}
|
||||
alternateHref={loginHref("/auth/admin-login", next)}
|
||||
alternateLabel="管理员登录"
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -38,7 +36,3 @@ export default async function LoginPage({
|
||||
function singleParam(value: string | string[] | undefined): string | undefined {
|
||||
return Array.isArray(value) ? value[0] : value;
|
||||
}
|
||||
|
||||
function loginHref(path: string, next: string): string {
|
||||
return `${path}?next=${encodeURIComponent(next)}`;
|
||||
}
|
||||
Reference in new issue
Block a user