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 new file mode 100644 index 0000000000..fdc4c6cb35 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/apps/app/app-auth.controller.ts @@ -0,0 +1,9 @@ +import { UMB_AUTH_CONTEXT } from '@umbraco-cms/backoffice/auth'; +import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; + +export class UmbAppAuthController extends UmbControllerBase { + async makeAuthorizationRequest() { + const authContext = await this.getContext(UMB_AUTH_CONTEXT); + return authContext.makeAuthorizationRequest(); + } +} diff --git a/src/Umbraco.Web.UI.Client/src/apps/app/app.element.ts b/src/Umbraco.Web.UI.Client/src/apps/app/app.element.ts index d104ccab6c..89ab404a0f 100644 --- a/src/Umbraco.Web.UI.Client/src/apps/app/app.element.ts +++ b/src/Umbraco.Web.UI.Client/src/apps/app/app.element.ts @@ -1,6 +1,7 @@ import type { UmbAppErrorElement } from './app-error.element.js'; import { UmbAppContext } from './app.context.js'; import { UmbServerConnection } from './server-connection.js'; +import { UmbAppAuthController } from './app-auth.controller.js'; import type { UMB_AUTH_CONTEXT } from '@umbraco-cms/backoffice/auth'; import { UMB_STORAGE_REDIRECT_URL, UmbAuthContext } from '@umbraco-cms/backoffice/auth'; import { css, html, customElement, property } from '@umbraco-cms/backoffice/external/lit'; @@ -59,6 +60,7 @@ export class UmbAppElement extends UmbLitElement { #umbIconRegistry = new UmbIconRegistry(); #uuiIconRegistry = new UUIIconRegistryEssential(); #serverConnection?: UmbServerConnection; + #authController = new UmbAppAuthController(this); constructor() { super(); @@ -184,7 +186,7 @@ export class UmbAppElement extends UmbLitElement { } #isAuthorizedGuard(): Guard { - return () => { + return async () => { if (!this.#authContext) { throw new Error('[Fatal] AuthContext requested before it was initialized'); } @@ -197,7 +199,7 @@ export class UmbAppElement extends UmbLitElement { window.sessionStorage.setItem(UMB_STORAGE_REDIRECT_URL, location.href); // Make a request to the auth server to start the auth flow - this.#authContext.makeAuthorizationRequest(); + await this.#authController.makeAuthorizationRequest(); // Return false to prevent the route from being rendered return false;