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 b9c00be403..491c36076f 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 @@ -5,7 +5,7 @@ import { UserResource } from '@umbraco-cms/backoffice/backend-api'; import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; import { UmbObjectState } from '@umbraco-cms/backoffice/observable-api'; import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources'; -import { ReplaySubject } from '@umbraco-cms/backoffice/external/rxjs'; +import { ReplaySubject, firstValueFrom } from '@umbraco-cms/backoffice/external/rxjs'; export class UmbAuthContext implements IUmbAuth { #currentUser = new UmbObjectState(undefined); @@ -46,4 +46,9 @@ export class UmbAuthContext implements IUmbAuth { signOut(): Promise { return this.#authFlow.signOut(); } + + async isUserCurrentUser(userId: string): Promise { + const currentUser = await firstValueFrom(this.currentUser); + return currentUser?.id === userId; + } } 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 b70031f8d7..53b82417dd 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 @@ -37,4 +37,9 @@ export interface IUmbAuth { * Sign out the current user. */ signOut(): Promise; + + /** + * Check if the given user is the current user. + */ + isUserCurrentUser(userId: string): Promise; }