feat: 添加重置邀请码验证状态功能,并在退出登录时调用

This commit is contained in:
Roe-xin
2026-01-27 20:16:13 +08:00
parent 31419e93a1
commit 6ef7e976cc
2 changed files with 36 additions and 2 deletions

View File

@ -368,3 +368,25 @@ export async function checkInvitationStatus(): Promise<InvitationStatusResponse>
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;
}
}

View File

@ -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],