From 4177b038fd6d42a198e6fb436738e29d3fac57da Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Fri, 26 Apr 2024 15:23:48 +0200 Subject: [PATCH] order properties and rename isTimeout to timeoutSignal --- .../src/apps/app/app-auth.controller.ts | 2 +- .../src/packages/core/auth/auth-flow.ts | 4 ++ .../src/packages/core/auth/auth.context.ts | 40 +++++++++---------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/apps/app/app-auth.controller.ts b/src/Umbraco.Web.UI.Client/src/apps/app/app-auth.controller.ts index 982824f5c2..19d7e98dc3 100644 --- a/src/Umbraco.Web.UI.Client/src/apps/app/app-auth.controller.ts +++ b/src/Umbraco.Web.UI.Client/src/apps/app/app-auth.controller.ts @@ -18,7 +18,7 @@ export class UmbAppAuthController extends UmbControllerBase { // Observe the user's authorization state and start the authorization flow if the user is not authorized this.observe( - context.isTimeout, + context.timeoutSignal, () => { this.#firstTimeLoggingIn = false; this.makeAuthorizationRequest('timedOut'); diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth-flow.ts b/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth-flow.ts index 58f547d8a8..89e4f0a1e0 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth-flow.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth-flow.ts @@ -97,6 +97,10 @@ export class UmbAuthFlow { // tokens #tokenResponse?: TokenResponse; + /** + * This signal will emit when the authorization flow is complete. + * @remark It will also emit if there is an error during the authorization flow. + */ authorizationSignal = new Subject(); constructor( diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth.context.ts b/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth.context.ts index a9cc8ad18c..a9aeae560e 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth.context.ts @@ -10,33 +10,13 @@ import { ReplaySubject, Subject, firstValueFrom, switchMap } from '@umbraco-cms/ export class UmbAuthContext extends UmbContextBase { #isAuthorized = new UmbBooleanState(false); - - /** - * Observable that emits true if the user is authorized, otherwise false. - * @remark It will only emit when the authorization state changes. - */ - readonly isAuthorized = this.#isAuthorized.asObservable(); - // Timeout is different from `isAuthorized` because it can occur repeatedly #isTimeout = new Subject(); - - /** - * Observable that emits when the user has timed out, i.e. the token has expired. - * This can be used to show a timeout message to the user. - * @remark It can emit multiple times if more than one request is made after the token has expired. - */ - readonly isTimeout = this.#isTimeout.asObservable(); - /** * Observable that emits true when the auth context is initialized. * @remark It will only emit once and then complete itself. */ #isInitialized = new ReplaySubject(1); - - get authorizationSignal() { - return this.#authFlow.authorizationSignal; - } - #isBypassed = false; #serverUrl; #backofficePath; @@ -45,6 +25,26 @@ export class UmbAuthContext extends UmbContextBase { #authWindowProxy?: WindowProxy | null; #previousAuthUrl?: string; + /** + * Observable that emits true if the user is authorized, otherwise false. + * @remark It will only emit when the authorization state changes. + */ + readonly isAuthorized = this.#isAuthorized.asObservable(); + + /** + * Observable that acts as a signal and emits when the user has timed out, i.e. the token has expired. + * This can be used to show a timeout message to the user. + * @remark It can emit multiple times if more than one request is made after the token has expired. + */ + readonly timeoutSignal = this.#isTimeout.asObservable(); + + /** + * Observable that acts as a signal for when the authorization state changes. + */ + get authorizationSignal() { + return this.#authFlow.authorizationSignal; + } + constructor(host: UmbControllerHost, serverUrl: string, backofficePath: string, isBypassed: boolean) { super(host, UMB_AUTH_CONTEXT); this.#isBypassed = isBypassed;