@@ -10,6 +10,7 @@ import fetch from 'node-fetch';
1010import { accountViewDataProvider } from '../tree-view-providers/account-view-data-provider' ;
1111import { postsDataProvider } from '../tree-view-providers/posts-data-provider' ;
1212import { postCategoriesDataProvider } from '../tree-view-providers/categories-view-data-provider' ;
13+ import { checkIsAccessTokenExpired } from '../utils/check-access-token-expired' ;
1314
1415const isAuthorizedStorageKey = 'isAuthorized' ;
1516
@@ -18,7 +19,12 @@ export class AccountService extends vscode.Disposable {
1819
1920 buildBearerAuthorizationHeader ( accessToken ?: string ) : [ string , string ] {
2021 accessToken ??= this . curUser . authorizationInfo ?. accessToken ;
21- return [ 'Authorization' , `Bearer ${ accessToken } ` ] ;
22+ let expired = checkIsAccessTokenExpired ( accessToken ! ) ;
23+ if ( expired ) {
24+ this . logout ( ) ;
25+ this . alertLoginStatusExpired ( ) ;
26+ }
27+ return [ 'Authorization' , `Bearer ${ expired ? '' : accessToken } ` ] ;
2228 }
2329
2430 private _curUser ?: UserInfo ;
@@ -145,6 +151,18 @@ export class AccountService extends vscode.Disposable {
145151 delete obj . picture ;
146152 return Object . assign ( new UserInfo ( authorizationInfo ) , obj , { avatar : obj . picture } ) ;
147153 }
154+
155+ private async alertLoginStatusExpired ( ) {
156+ const options = [ '登录' ] ;
157+ const input = await vscode . window . showInformationMessage (
158+ '登录状态已过期, 请重新登录' ,
159+ { modal : true } as vscode . MessageOptions ,
160+ ...options
161+ ) ;
162+ if ( input === options [ 0 ] ) {
163+ await this . login ( ) ;
164+ }
165+ }
148166}
149167
150168export const accountService = AccountService . instance ;
0 commit comments