From 5d22f6bcdf6a259be21b2b913f2821c7f80574e5 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Tue, 24 Oct 2023 11:07:19 +0200 Subject: [PATCH] construct UmbAuthFlow internally in UmbAuthContext --- .../src/shared/auth/auth.context.ts | 15 +++++++++++---- .../src/shared/auth/index.ts | 5 ++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.ts b/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.ts index b9c00be403..821484e919 100644 --- a/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.ts +++ b/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.ts @@ -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(undefined); readonly currentUser = this.#currentUser.asObservable(); - readonly isLoggedIn = new ReplaySubject(1); + readonly isLoggedIn = new BehaviorSubject(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 { return this.#authFlow.setInitialState(); } diff --git a/src/Umbraco.Web.UI.Client/src/shared/auth/index.ts b/src/Umbraco.Web.UI.Client/src/shared/auth/index.ts index e32f1d152b..b4989d9932 100644 --- a/src/Umbraco.Web.UI.Client/src/shared/auth/index.ts +++ b/src/Umbraco.Web.UI.Client/src/shared/auth/index.ts @@ -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';