last correction

This commit is contained in:
Niels Lyngsø
2023-11-07 21:04:39 +01:00
parent 547ec99477
commit 93f13ea8f0
2 changed files with 7 additions and 8 deletions

View File

@@ -144,7 +144,7 @@ export class UmbWorkspacePropertyContext<ValueType = any> extends UmbBaseControl
}
public destroy(): void {
this.#data.unsubscribe();
this.#data.complete();
this._providerController.destroy(); // This would also be handled by the controller host, but if someone wanted to replace/remove this context without the host being destroyed. Then we have clean up out selfs here.
}
}

View File

@@ -2,27 +2,26 @@ import { IUmbAuth } from './auth.interface.js';
import { UmbAuthFlow } from './auth-flow.js';
import { UmbLoggedInUser } from './types.js';
import { UserResource } from '@umbraco-cms/backoffice/backend-api';
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import { UmbBaseController, UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import { UmbBooleanState, UmbObjectState } from '@umbraco-cms/backoffice/observable-api';
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
import { firstValueFrom } from '@umbraco-cms/backoffice/external/rxjs';
export class UmbAuthContext implements IUmbAuth {
export class UmbAuthContext extends UmbBaseController implements IUmbAuth {
#currentUser = new UmbObjectState<UmbLoggedInUser | undefined>(undefined);
readonly currentUser = this.#currentUser.asObservable();
readonly isLoggedIn = new UmbBooleanState<boolean>(false);
readonly languageIsoCode = this.#currentUser.asObservablePart((user) => user?.languageIsoCode ?? 'en-us');
#host;
#authFlow;
constructor(host: UmbControllerHostElement, serverUrl: string, redirectUrl: string) {
this.#host = host;
super(host)
this.#authFlow = new UmbAuthFlow(serverUrl, redirectUrl);
this.isLoggedIn.subscribe((isLoggedIn) => {
this.observe(this.isLoggedIn, (isLoggedIn) => {
if (isLoggedIn) {
this.fetchCurrentUser();
}
@@ -45,7 +44,7 @@ export class UmbAuthContext implements IUmbAuth {
}
async fetchCurrentUser(): Promise<UmbLoggedInUser | undefined> {
const { data } = await tryExecuteAndNotify(this.#host, UserResource.getUserCurrent());
const { data } = await tryExecuteAndNotify(this._host, UserResource.getUserCurrent());
this.#currentUser.next(data);