add method to check if a user is the currentUser

This commit is contained in:
Mads Rasmussen
2023-10-15 20:54:24 +02:00
parent a177ebfd08
commit b65e61dde6
2 changed files with 11 additions and 1 deletions

View File

@@ -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<UmbLoggedInUser | undefined>(undefined);
@@ -46,4 +46,9 @@ export class UmbAuthContext implements IUmbAuth {
signOut(): Promise<void> {
return this.#authFlow.signOut();
}
async isUserCurrentUser(userId: string): Promise<boolean> {
const currentUser = await firstValueFrom(this.currentUser);
return currentUser?.id === userId;
}
}

View File

@@ -37,4 +37,9 @@ export interface IUmbAuth {
* Sign out the current user.
*/
signOut(): Promise<void>;
/**
* Check if the given user is the current user.
*/
isUserCurrentUser(userId: string): Promise<boolean>;
}