last correction
This commit is contained in:
@@ -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.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user