-
- {broken ? t.loginInvalid : (email ?? t.signedIn)}
- {planLabel(plan) && !broken && ` · ${planLabel(plan)}`}
-
+
+
+ {who || (broken ? t.loginInvalid : t.signedIn)}
+
+ {broken && who && (
+
+ {t.loginInvalid}
+
+ )}
+
{broken ? (
{oauth?.failure ? coreText(oauth.failure) : t.needsLogin}
) : (
diff --git a/src/upstreams/ChatgptLoginDialog.i18n.tsx b/src/upstreams/ChatgptLoginDialog.i18n.tsx
index 5cd7c510..af9fc00d 100644
--- a/src/upstreams/ChatgptLoginDialog.i18n.tsx
+++ b/src/upstreams/ChatgptLoginDialog.i18n.tsx
@@ -35,6 +35,8 @@ export const chatgptLoginText = messages(
deviceWaiting: "输入完成后此处会自动继续。",
deviceWarning: "登录码有效期 15 分钟。只输入这里显示的这一个;由他人提供的登录码请勿输入。",
done: (provider: ReactNode) => <>已登录,上游 {provider} 已写入配置。>,
+ account: (email: string, plan: string | null) =>
+ plan ? `账号 ${email},订阅类型 ${plan}。` : `账号 ${email}。`,
plan: (plan: string) => `订阅类型 ${plan}。`,
doneHint: "模型范围、计费方式等可在该上游的编辑对话框中调整。",
finish: "完成",
@@ -76,6 +78,8 @@ export const chatgptLoginText = messages(
deviceWaiting: "Sign-in continues here automatically once the code is entered.",
deviceWarning: "The sign-in code is valid for 15 minutes. Enter only the code shown here; do not enter a sign-in code provided by someone else.",
done: (provider: ReactNode) => <>Signed in. The upstream {provider} has been saved to the config.>,
+ account: (email: string, plan: string | null) =>
+ plan ? `Account: ${email}, plan: ${plan}.` : `Account: ${email}.`,
plan: (plan: string) => `Plan: ${plan}.`,
doneHint: "Model scope, billing and other settings can be changed in the upstream's edit dialog.",
finish: "Done",
diff --git a/src/upstreams/ChatgptLoginDialog.tsx b/src/upstreams/ChatgptLoginDialog.tsx
index 12a507c1..4029fba5 100644
--- a/src/upstreams/ChatgptLoginDialog.tsx
+++ b/src/upstreams/ChatgptLoginDialog.tsx
@@ -16,7 +16,7 @@ import { Field, FieldLabel } from "@/ui/field";
import { Input } from "@/ui/input";
import { NativeSelect, NativeSelectOption } from "@/ui/native-select";
import { StatusLabel } from "@/ui/status-dot";
-import type { ChatgptLoginMode, ChatgptLoginStatus, ChatgptPlan, CoreEvent, Overview } from "@/types";
+import type { AccountView, ChatgptLoginMode, ChatgptLoginStatus, CoreEvent, Overview } from "@/types";
import { textOf, useText } from "@/i18n";
import { commonText } from "@/i18n/common.i18n";
import { api } from "./api";
@@ -37,7 +37,8 @@ type Phase =
| { at: "browser"; id: string }
/** 码已经拿到,等用户在另一台设备上输 */
| { at: "device"; id: string; code: string; url: string }
- | { at: "done"; provider: string; plan: ChatgptPlan | null };
+ /** `account`:登上的是哪个账号,和列表、编辑对话框读的是同一份(上游视图的 `oauth.account`) */
+ | { at: "done"; provider: string; account: AccountView | null };
/**
* 用 ChatGPT 账号新建上游,或给已有的账号换一次凭据。
@@ -91,12 +92,22 @@ export function ChatgptLoginDialog({
}, []);
const waiting = phase.at === "browser" || phase.at === "device" ? phase.id : null;
+ /** 已经收过尾的那次登录。事件和轮询都会报结果,只收一次 */
+ const settled = useRef
(null);
function settle(s: ChatgptLoginStatus) {
- if (!alive.current || s.status === "pending") return;
+ if (!alive.current || s.status === "pending" || settled.current === s.id) return;
+ settled.current = s.id;
if (s.status === "done" && s.provider) {
- setPhase({ at: "done", provider: s.provider, plan: s.plan ?? null });
- onSaved(s.provider);
+ const provider = s.provider;
+ onSaved(provider);
+ // 登上的是哪个账号,问上游视图:和列表、编辑对话框说的是同一份。问不到就只说上游
+ void api
+ .signedInAs(provider)
+ .catch(() => null)
+ .then((account) => {
+ if (alive.current) setPhase({ at: "done", provider, account });
+ });
return;
}
setPhase({ at: "form" });
@@ -169,7 +180,10 @@ export function ChatgptLoginDialog({
const nameTaken = !relogin && taken.includes(name.trim()) && phase.at === "form";
const canStart = name.trim().length > 0 && !nameTaken && understood && !busy;
- const planName = phase.at === "done" ? planLabel(phase.plan) : null;
+ // 登上的账号:邮箱和套餐,令牌里读不出来的那一项不说
+ const account = phase.at === "done" ? phase.account : null;
+ const plan = planLabel(account?.plan);
+ const who = account?.email ? t.account(account.email, plan) : plan ? t.plan(plan) : null;
return (