move auth request logic to an auth controller to split up the logic
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user