From 6ef7e976cccc58a023dcdcef73692e9b651a0569 Mon Sep 17 00:00:00 2001 From: Roe-xin Date: Tue, 27 Jan 2026 20:16:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E9=82=80=E8=AF=B7=E7=A0=81=E9=AA=8C=E8=AF=81=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=B9=B6=E5=9C=A8=E9=80=80=E5=87=BA?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=97=B6=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/apiClient.ts | 22 ++++++++++++++++++++++ src/services/icCoderAuthProvider.ts | 16 ++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/services/apiClient.ts b/src/services/apiClient.ts index 466034e..ac08da0 100644 --- a/src/services/apiClient.ts +++ b/src/services/apiClient.ts @@ -368,3 +368,25 @@ export async function checkInvitationStatus(): Promise method: "GET", }); } + +/** + * 重置邀请码验证状态(退出登录时调用) + * POST /api/invitation/reset + */ +export async function resetInvitationVerification(): Promise<{ code: number; msg: string }> { + console.log("[API] 重置邀请码验证状态"); + try { + const response = await request<{ code: number; msg: string }>( + "/api/invitation/reset", + { + method: "POST", + }, + ); + console.log("[API] 重置邀请码验证状态 - 响应:", JSON.stringify(response)); + return response; + } catch (error) { + console.warn("[API] 重置邀请码验证状态 - 错误:", error); + // 即使失败也不影响退出登录流程 + throw error; + } +} diff --git a/src/services/icCoderAuthProvider.ts b/src/services/icCoderAuthProvider.ts index 4a34195..153317b 100644 --- a/src/services/icCoderAuthProvider.ts +++ b/src/services/icCoderAuthProvider.ts @@ -4,6 +4,7 @@ import * as path from "path"; import * as fs from "fs"; import { onTokenReceived, type UserInfo, clearUserInfo } from "./userService"; import { getConfig } from "../config/settings"; +import { resetInvitationVerification } from "./apiClient"; /** * IC Coder Authentication Provider @@ -142,13 +143,24 @@ export class ICCoderAuthenticationProvider const sessionIndex = this._sessions.findIndex((s) => s.id === sessionId); if (sessionIndex > -1) { const session = this._sessions[sessionIndex]; + + // 1. 先调用后端重置邀请码验证状态 + try { + await resetInvitationVerification(); + console.log("[AuthProvider] 邀请码验证状态已重置"); + } catch (error) { + console.warn("[AuthProvider] 重置邀请码验证状态失败,但继续退出流程:", error); + // 即使失败也继续退出流程 + } + + // 2. 清除本地 session this._sessions.splice(sessionIndex, 1); await this.saveSessions(); - // 清除用户信息缓存 + // 3. 清除用户信息缓存 await clearUserInfo(); - // 触发会话变化事件 + // 4. 触发会话变化事件 this._onDidChangeSessions.fire({ added: [], removed: [session],