feat: 添加重置邀请码验证状态功能,并在退出登录时调用
This commit is contained in:
@ -368,3 +368,25 @@ export async function checkInvitationStatus(): Promise<InvitationStatusResponse>
|
|||||||
method: "GET",
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import * as path from "path";
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { onTokenReceived, type UserInfo, clearUserInfo } from "./userService";
|
import { onTokenReceived, type UserInfo, clearUserInfo } from "./userService";
|
||||||
import { getConfig } from "../config/settings";
|
import { getConfig } from "../config/settings";
|
||||||
|
import { resetInvitationVerification } from "./apiClient";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IC Coder Authentication Provider
|
* IC Coder Authentication Provider
|
||||||
@ -142,13 +143,24 @@ export class ICCoderAuthenticationProvider
|
|||||||
const sessionIndex = this._sessions.findIndex((s) => s.id === sessionId);
|
const sessionIndex = this._sessions.findIndex((s) => s.id === sessionId);
|
||||||
if (sessionIndex > -1) {
|
if (sessionIndex > -1) {
|
||||||
const session = this._sessions[sessionIndex];
|
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);
|
this._sessions.splice(sessionIndex, 1);
|
||||||
await this.saveSessions();
|
await this.saveSessions();
|
||||||
|
|
||||||
// 清除用户信息缓存
|
// 3. 清除用户信息缓存
|
||||||
await clearUserInfo();
|
await clearUserInfo();
|
||||||
|
|
||||||
// 触发会话变化事件
|
// 4. 触发会话变化事件
|
||||||
this._onDidChangeSessions.fire({
|
this._onDidChangeSessions.fire({
|
||||||
added: [],
|
added: [],
|
||||||
removed: [session],
|
removed: [session],
|
||||||
|
|||||||
Reference in New Issue
Block a user