Revert "rename UmbAuth and other fixes"

This reverts commit a78c1d1b14.
This commit is contained in:
Niels Lyngsø
2023-11-09 14:45:47 +01:00
parent a78c1d1b14
commit bc6922b789
5 changed files with 15 additions and 16 deletions

View File

@@ -186,7 +186,7 @@ export class UmbAppElement extends UmbLitElement {
async #setAuthStatus() {
if (this.bypassAuth === false) {
if (!this.#authContext) {
throw new Error('[Fatal] AuthContext requested before it was initialized');
throw new Error('[Fatal] AuthContext requested before it was initialised');
}
// Get service configuration from authentication server
@@ -200,8 +200,6 @@ export class UmbAppElement extends UmbLitElement {
// TODO: This feels like an od placement, move this into some method regarding starting the application/not install/...
this.#listenForLanguageChange();
this.#authContext?.checkAuthorization();
}
#redirect() {
@@ -241,13 +239,13 @@ export class UmbAppElement extends UmbLitElement {
}
}
#checkAuthorized(): boolean {
return this.#authContext?.checkAuthorization() ?? false;
#isAuthorized(): boolean {
return this.#authContext?.isAuthorized() ?? false;
}
#isAuthorizedGuard(): Guard {
return () => {
if (this.#checkAuthorized()) {
if (this.#isAuthorized()) {
return true;
}

View File

@@ -1,9 +1,9 @@
import { UmbAuth, UMB_AUTH_CONTEXT } from '@umbraco-cms/backoffice/auth';
import { IUmbAuth, UMB_AUTH_CONTEXT } from '@umbraco-cms/backoffice/auth';
import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api';
import { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
export const isCurrentUser = async (host: UmbControllerHost, userId: string) => {
let authContext: UmbAuth | undefined = undefined;
let authContext: IUmbAuth | undefined = undefined;
await new UmbContextConsumerController(host, UMB_AUTH_CONTEXT, (context) => {
authContext = context;

View File

@@ -1,4 +1,4 @@
import { UmbAuth } from './auth.interface.js';
import { IUmbAuth } from './auth.interface.js';
import { UmbAuthFlow } from './auth-flow.js';
import { UmbLoggedInUser } from './types.js';
import { UserResource } from '@umbraco-cms/backoffice/backend-api';
@@ -7,7 +7,7 @@ import { UmbBooleanState, UmbObjectState } from '@umbraco-cms/backoffice/observa
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
import { firstValueFrom } from '@umbraco-cms/backoffice/external/rxjs';
export class UmbAuthContext extends UmbBaseController implements UmbAuth {
export class UmbAuthContext extends UmbBaseController implements IUmbAuth {
#currentUser = new UmbObjectState<UmbLoggedInUser | undefined>(undefined);
readonly currentUser = this.#currentUser.asObservable();
@@ -47,8 +47,8 @@ export class UmbAuthContext extends UmbBaseController implements UmbAuth {
return this.#authFlow?.makeAuthorizationRequest();
}
checkAuthorization() {
return this.#authFlow?.checkAuthorization() ?? true;
isAuthorized() {
return this.#authFlow?.isAuthorized() ?? true;
}
setInitialState(): Promise<void> {

View File

@@ -1,7 +1,7 @@
import type { UmbLoggedInUser } from './types.js';
import type { Observable } from '@umbraco-cms/backoffice/external/rxjs';
export interface UmbAuth {
export interface IUmbAuth {
/**
* Initiates the login flow.
*/
@@ -15,7 +15,8 @@ export interface UmbAuth {
/**
* Checks if there is a token and it is still valid.
*/
checkAuthorization(): boolean;
isAuthorized(): boolean;
/**
* Gets the latest token from the Management API.
* If the token is expired, it will be refreshed.

View File

@@ -1,6 +1,6 @@
import { UmbAuth } from './auth.interface.js';
import { IUmbAuth } from './auth.interface.js';
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
export const UMB_AUTH_CONTEXT = new UmbContextToken<UmbAuth>(
export const UMB_AUTH_CONTEXT = new UmbContextToken<IUmbAuth>(
'UmbAuthContext'
);