fix: 修复登录状态相关问题
- 修复登录时VSCode弹出"账户不一致"确认框的问题 - 添加SSE业务错误码401检测,正确触发重新登录流程 - 修复侧边栏登录状态不刷新的问题,添加onDidChangeSessions监听
This commit is contained in:
@ -128,15 +128,18 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
"ic-coder.login",
|
||||
async () => {
|
||||
try {
|
||||
// 检查是否有现有 session
|
||||
const existingSession = await vscode.authentication.getSession("iccoder", [], { createIfNone: false });
|
||||
if (existingSession) {
|
||||
// 有旧 session,使用 forceNewSession 强制创建新 session
|
||||
await vscode.authentication.getSession("iccoder", [], { forceNewSession: true });
|
||||
} else {
|
||||
// 没有旧 session,使用 createIfNone 创建新 session
|
||||
await vscode.authentication.getSession("iccoder", [], { createIfNone: true });
|
||||
// 先清除 session 偏好,避免 VSCode 弹出"账户不一致"确认框
|
||||
try {
|
||||
await vscode.authentication.getSession("iccoder", [], {
|
||||
clearSessionPreference: true,
|
||||
createIfNone: false
|
||||
});
|
||||
} catch {
|
||||
// 忽略错误
|
||||
}
|
||||
|
||||
// 创建新 session
|
||||
await vscode.authentication.getSession("iccoder", [], { createIfNone: true });
|
||||
} catch (error) {
|
||||
vscode.window.showErrorMessage(`登录失败: ${error}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user