diff --git a/README.md b/README.md index cb3f3db..96f6fcc 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ Step 3 使用的注册邮箱。 ### Step 6: Login via OAuth -重新打开 OAuth 链接,使用刚注册的账号登录。 +在登录前会先重新获取一遍最新的 VPS OAuth 链接,再使用刚注册的账号登录。 支持: diff --git a/background.js b/background.js index 2168f92..04a49c8 100644 --- a/background.js +++ b/background.js @@ -1734,17 +1734,34 @@ async function executeStep5(state) { // Step 6: Login ChatGPT (Background opens tab, chatgpt.js handles login) // ============================================================ -async function executeStep6(state) { - if (!state.oauthUrl) { - throw new Error('缺少 OAuth 链接,请先完成步骤 1。'); +async function refreshOAuthUrlBeforeStep6(state) { + if (!state.vpsUrl) { + throw new Error('尚未配置 VPS 地址,请先在侧边栏填写。'); } + + await addLog('步骤 6:正在刷新登录用的 OAuth 链接...'); + const waitForFreshOAuth = waitForStepComplete(1, 120000); + await executeStep1(state); + await waitForFreshOAuth; + + const latestState = await getState(); + if (!latestState.oauthUrl) { + throw new Error('刷新 OAuth 链接后仍未拿到可用链接。'); + } + + return latestState.oauthUrl; +} + +async function executeStep6(state) { if (!state.email) { throw new Error('缺少邮箱地址,请先完成步骤 3。'); } - await addLog('步骤 6:正在打开用于登录的 OAuth 链接...'); + const oauthUrl = await refreshOAuthUrlBeforeStep6(state); + + await addLog('步骤 6:正在打开最新 OAuth 链接并登录...'); // Reuse the signup-page tab — navigate it to the OAuth URL - await reuseOrCreateTab('signup-page', state.oauthUrl); + await reuseOrCreateTab('signup-page', oauthUrl); // signup-page.js will inject (same auth.openai.com domain) and handle login await sendToContentScript('signup-page', { diff --git a/sidepanel/sidepanel.html b/sidepanel/sidepanel.html index 066a153..7a5d1ba 100644 --- a/sidepanel/sidepanel.html +++ b/sidepanel/sidepanel.html @@ -145,7 +145,7 @@