Parcourir la source

Forces a logout if no valid auth is found

main
Eric Amodio il y a 2 ans
Parent
révision
50b1b3d478
1 fichiers modifiés avec 13 ajouts et 2 suppressions
  1. +13
    -2
      src/premium/subscription/subscriptionService.ts

+ 13
- 2
src/premium/subscription/subscriptionService.ts Voir le fichier

@ -1,6 +1,7 @@
import { import {
authentication, authentication,
AuthenticationSession, AuthenticationSession,
AuthenticationSessionsChangeEvent,
version as codeVersion, version as codeVersion,
commands, commands,
Disposable, Disposable,
@ -40,6 +41,7 @@ import { createFromDateDelta } from '../../system/date';
import { gate } from '../../system/decorators/gate'; import { gate } from '../../system/decorators/gate';
import { debug, log } from '../../system/decorators/log'; import { debug, log } from '../../system/decorators/log';
import { memoize } from '../../system/decorators/memoize'; import { memoize } from '../../system/decorators/memoize';
import { once } from '../../system/function';
import { pluralize } from '../../system/string'; import { pluralize } from '../../system/string';
// TODO: What user-agent should we use? // TODO: What user-agent should we use?
@ -64,7 +66,10 @@ export class SubscriptionService implements Disposable {
private _statusBarSubscription: StatusBarItem | undefined; private _statusBarSubscription: StatusBarItem | undefined;
constructor(private readonly container: Container) { constructor(private readonly container: Container) {
this._disposable = this.container.onReady(this.onReady, this);
this._disposable = Disposable.from(
once(container.onReady)(this.onReady, this),
authentication.onDidChangeSessions(this.onAuthenticationChanged, this),
);
this.changeSubscription(this.getStoredSubscription(), true); this.changeSubscription(this.getStoredSubscription(), true);
setTimeout(() => void this.ensureSession(false), 10000); setTimeout(() => void this.ensureSession(false), 10000);
@ -76,6 +81,12 @@ export class SubscriptionService implements Disposable {
this._disposable.dispose(); this._disposable.dispose();
} }
private onAuthenticationChanged(e: AuthenticationSessionsChangeEvent): void {
if (e.provider.id !== SubscriptionService.authenticationProviderId) return;
void this.ensureSession(false);
}
@memoize() @memoize()
private get baseApiUri(): Uri { private get baseApiUri(): Uri {
const { env } = this.container; const { env } = this.container;
@ -515,7 +526,7 @@ export class SubscriptionService implements Disposable {
} }
if (session == null) { if (session == null) {
this.updateContext();
this.logout();
return session ?? null; return session ?? null;
} }

Chargement…
Annuler
Enregistrer