move auth request logic to an auth controller to split up the logic

This commit is contained in:
Jacob Overgaard
2024-04-04 12:03:15 +02:00
parent 22e7742d47
commit 762368c3a6
2 changed files with 13 additions and 2 deletions

View File

@@ -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();
}
}

View File

@@ -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;