construct UmbAuthFlow internally in UmbAuthContext
This commit is contained in:
@@ -5,20 +5,20 @@ import { UserResource } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbObjectState } from '@umbraco-cms/backoffice/observable-api';
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
|
||||
import { ReplaySubject } from '@umbraco-cms/backoffice/external/rxjs';
|
||||
import { BehaviorSubject } from '@umbraco-cms/backoffice/external/rxjs';
|
||||
|
||||
export class UmbAuthContext implements IUmbAuth {
|
||||
#currentUser = new UmbObjectState<UmbLoggedInUser | undefined>(undefined);
|
||||
readonly currentUser = this.#currentUser.asObservable();
|
||||
readonly isLoggedIn = new ReplaySubject<boolean>(1);
|
||||
readonly isLoggedIn = new BehaviorSubject<boolean>(false);
|
||||
readonly languageIsoCode = this.#currentUser.asObservablePart((user) => user?.languageIsoCode ?? 'en-us');
|
||||
|
||||
#host;
|
||||
#authFlow;
|
||||
|
||||
constructor(host: UmbControllerHostElement, authFlow: UmbAuthFlow) {
|
||||
constructor(host: UmbControllerHostElement, serverUrl: string, redirectUrl: string) {
|
||||
this.#host = host;
|
||||
this.#authFlow = authFlow;
|
||||
this.#authFlow = new UmbAuthFlow(serverUrl, redirectUrl);
|
||||
|
||||
this.isLoggedIn.subscribe((isLoggedIn) => {
|
||||
if (isLoggedIn) {
|
||||
@@ -27,6 +27,13 @@ export class UmbAuthContext implements IUmbAuth {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates the login flow.
|
||||
*/
|
||||
login(): void {
|
||||
return this.#authFlow.makeAuthorizationRequest();
|
||||
}
|
||||
|
||||
setInitialState(): Promise<void> {
|
||||
return this.#authFlow.setInitialState();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
export type { IUmbAuth } from './auth.interface.js';
|
||||
export { UmbAuthFlow } from './auth-flow.js';
|
||||
export { UmbAuthContext } from './auth.context.js';
|
||||
export * from './auth.interface.js';
|
||||
export * from './auth.context.js';
|
||||
|
||||
export * from './types.js';
|
||||
export * from './auth.token.js';
|
||||
|
||||
Reference in New Issue
Block a user