From cea210a56c04a8b8a84864a02aa29a92c3ec668b Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Tue, 24 Oct 2023 14:38:08 +0200 Subject: [PATCH] export the isAuthorized function --- src/Umbraco.Web.UI.Client/src/shared/auth/auth-flow.ts | 2 +- src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.ts | 4 ++++ src/Umbraco.Web.UI.Client/src/shared/auth/auth.interface.ts | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI.Client/src/shared/auth/auth-flow.ts b/src/Umbraco.Web.UI.Client/src/shared/auth/auth-flow.ts index a57a410c9b..c776944107 100644 --- a/src/Umbraco.Web.UI.Client/src/shared/auth/auth-flow.ts +++ b/src/Umbraco.Web.UI.Client/src/shared/auth/auth-flow.ts @@ -219,7 +219,7 @@ export class UmbAuthFlow { * * @returns true if the user is logged in, false otherwise. */ - loggedIn(): boolean { + isAuthorized(): boolean { return !!this.#accessTokenResponse && this.#accessTokenResponse.isValid(); } 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 32bc11fd29..0a25ed014d 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 @@ -34,6 +34,10 @@ export class UmbAuthContext implements IUmbAuth { return this.#authFlow.makeAuthorizationRequest(); } + isAuthorized() { + return this.#authFlow.isAuthorized(); + } + setInitialState(): Promise { return this.#authFlow.setInitialState(); } diff --git a/src/Umbraco.Web.UI.Client/src/shared/auth/auth.interface.ts b/src/Umbraco.Web.UI.Client/src/shared/auth/auth.interface.ts index 9e197cd717..82bf9d544e 100644 --- a/src/Umbraco.Web.UI.Client/src/shared/auth/auth.interface.ts +++ b/src/Umbraco.Web.UI.Client/src/shared/auth/auth.interface.ts @@ -12,6 +12,11 @@ export interface IUmbAuth { */ setInitialState(): Promise; + /** + * Checks if there is a token and it is still valid. + */ + isAuthorized(): boolean; + /** * Gets the latest token from the Management API. * If the token is expired, it will be refreshed.