feat:实现Token过期检查和自动清除机制
主要改动: - 在插件激活时检查Token是否过期,过期则自动清除session - 修复Token检查逻辑,从session.accessToken获取Token而非globalState - 在消息发送前检查Token有效性,过期则提示重新登录 - 优化ICHelperPanel和ICViewProvider的Token过期处理 - 修复退出登录命令名错误(iccoder.logout -> ic-coder.logout) - 添加Token过期检查文档文档
This commit is contained in:
@ -202,6 +202,20 @@ export class ICViewProvider implements vscode.WebviewViewProvider {
|
||||
localResourceRoots: [vscode.Uri.joinPath(this.extensionUri, "media")],
|
||||
};
|
||||
|
||||
// 异步检查 token 是否过期并清除
|
||||
vscode.authentication.getSession("iccoder", [], { createIfNone: false })
|
||||
.then((session) => {
|
||||
const token = session?.accessToken;
|
||||
if (token && isTokenExpired(token)) {
|
||||
// 静默清除过期的 session
|
||||
this.context.globalState.update('icCoderSessions', []);
|
||||
this.context.globalState.update('icCoderUserInfo', undefined);
|
||||
console.log('[ICViewProvider] Token 已过期,已清除所有登录状态');
|
||||
}
|
||||
}, () => {
|
||||
// 忽略错误
|
||||
});
|
||||
|
||||
// 检查是否已登录(使用 Authentication API)
|
||||
this.checkLoginStatus().then((isLoggedIn) => {
|
||||
webviewView.webview.html = this.getWebviewContent(
|
||||
|
||||
Reference in New Issue
Block a user