Skip to content

Commit f412317

Browse files
authored
fix(login): force new session when login (#132)
1 parent 71bbf20 commit f412317

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/authentication/account-manager.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { OauthApi } from '@/services/oauth.api';
88
import { CnblogsAuthenticationProvider } from '@/authentication/authentication-provider';
99
import { CnblogsAuthenticationSession } from '@/authentication/session';
1010
import { BlogExportProvider } from '@/tree-view-providers/blog-export-provider';
11+
import { AlertService } from '@/services/alert.service';
1112

1213
const isAuthorizedStorageKey = 'isAuthorized';
1314

@@ -73,7 +74,7 @@ class AccountManager extends vscode.Disposable {
7374
}
7475

7576
async login() {
76-
await this.ensureSession({ createIfNone: true, forceNewSession: false });
77+
await this.ensureSession({ createIfNone: false, forceNewSession: true });
7778
}
7879

7980
async logout() {
@@ -116,8 +117,8 @@ class AccountManager extends vscode.Disposable {
116117
opt?: AuthenticationGetSessionOptions
117118
): Promise<CnblogsAuthenticationSession | undefined | null> {
118119
const session = await authentication.getSession(this._authenticationProvider.providerId, [], opt).then(
119-
s => (s ? CnblogsAuthenticationSession.parse(s) : null),
120-
() => null
120+
session => (session ? CnblogsAuthenticationSession.parse(session) : null),
121+
reason => AlertService.warning(`创建/获取 session 失败, ${reason}`)
121122
);
122123

123124
if (session != null && session.account.accountId < 0) {

src/authentication/authentication-provider.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,12 @@ export class CnblogsAuthenticationProvider implements AuthenticationProvider, Di
175175
protected async getAllSessions(): Promise<CnblogsAuthenticationSession[]> {
176176
const legacyToken = LegacyTokenStore.getAccessToken();
177177
if (legacyToken != null) {
178-
await this.onAccessTokenGranted({ accessToken: legacyToken }, { shouldFireSessionAddedEvent: false }).then(
179-
() => LegacyTokenStore.remove(),
180-
console.warn
181-
);
178+
await this.onAccessTokenGranted({ accessToken: legacyToken }, { shouldFireSessionAddedEvent: false })
179+
.then(undefined, console.warn)
180+
.finally(() => LegacyTokenStore.remove());
182181
}
183182

184-
if (this._allSessions == null) {
183+
if (this._allSessions == null || this._allSessions.length <= 0) {
185184
const sessions = JSON.parse((await this.secretStorage.get(this.sessionStorageKey)) ?? '[]') as
186185
| CnblogsAuthenticationSession[]
187186
| null

0 commit comments

Comments
 (0)