@@ -10,6 +10,7 @@ import fetch from 'node-fetch';
10
10
import { accountViewDataProvider } from '../tree-view-providers/account-view-data-provider' ;
11
11
import { postsDataProvider } from '../tree-view-providers/posts-data-provider' ;
12
12
import { postCategoriesDataProvider } from '../tree-view-providers/categories-view-data-provider' ;
13
+ import { checkIsAccessTokenExpired } from '../utils/check-access-token-expired' ;
13
14
14
15
const isAuthorizedStorageKey = 'isAuthorized' ;
15
16
@@ -18,7 +19,12 @@ export class AccountService extends vscode.Disposable {
18
19
19
20
buildBearerAuthorizationHeader ( accessToken ?: string ) : [ string , string ] {
20
21
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 } ` ] ;
22
28
}
23
29
24
30
private _curUser ?: UserInfo ;
@@ -145,6 +151,18 @@ export class AccountService extends vscode.Disposable {
145
151
delete obj . picture ;
146
152
return Object . assign ( new UserInfo ( authorizationInfo ) , obj , { avatar : obj . picture } ) ;
147
153
}
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
+ }
148
166
}
149
167
150
168
export const accountService = AccountService . instance ;
0 commit comments