From 1dba67ac4331fedef3b8fccef264779c5a3ec4eb Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Mon, 8 Apr 2024 10:16:24 +0200 Subject: [PATCH] export types from the appauth module to fix tests --- .../src/external/openid/index.ts | 14 ++--- .../umbraco-news-dashboard.element.ts | 58 ++++++------------- 2 files changed, 24 insertions(+), 48 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/external/openid/index.ts b/src/Umbraco.Web.UI.Client/src/external/openid/index.ts index ff18b32b45..8b049e918b 100644 --- a/src/Umbraco.Web.UI.Client/src/external/openid/index.ts +++ b/src/Umbraco.Web.UI.Client/src/external/openid/index.ts @@ -5,14 +5,12 @@ export { LocalStorageBackend, RedirectRequestHandler, RevokeTokenRequest, -} from '@openid/appauth'; -export { AuthorizationRequest } from '@openid/appauth/built/authorization_request'; -export { AuthorizationNotifier } from '@openid/appauth/built/authorization_request_handler'; -export { AuthorizationServiceConfiguration } from '@openid/appauth/built/authorization_service_configuration'; -export { + AuthorizationNotifier, + AuthorizationRequest, + AuthorizationServiceConfiguration, GRANT_TYPE_AUTHORIZATION_CODE, GRANT_TYPE_REFRESH_TOKEN, TokenRequest, -} from '@openid/appauth/built/token_request'; -export { TokenResponse } from '@openid/appauth/built/token_response'; -export type { LocationLike, StringMap } from '@openid/appauth/built/types'; + TokenResponse, +} from '@openid/appauth'; +export type { LocationLike, StringMap } from '@openid/appauth'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/umbraco-news/umbraco-news-dashboard.element.ts b/src/Umbraco.Web.UI.Client/src/packages/umbraco-news/umbraco-news-dashboard.element.ts index d9a5135dbb..3f605ebf38 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/umbraco-news/umbraco-news-dashboard.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/umbraco-news/umbraco-news-dashboard.element.ts @@ -1,61 +1,39 @@ -import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; -import { UMB_CURRENT_USER_CONTEXT } from '@umbraco-cms/backoffice/current-user'; -import { css, html, customElement, state } from '@umbraco-cms/backoffice/external/lit'; +import { UMB_AUTH_CONTEXT } from '../core/auth/auth.context.token.js'; +import { tryExecuteAndNotify } from '../core/resources/tryExecuteAndNotify.function.js'; +import { html, customElement, state } from '@umbraco-cms/backoffice/external/lit'; import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; +import { UserGroupResource, type UserGroupResponseModel } from '@umbraco-cms/backoffice/external/backend-api'; @customElement('umb-umbraco-news-dashboard') export class UmbUmbracoNewsDashboardElement extends UmbLitElement { - #currentUserContext?: typeof UMB_CURRENT_USER_CONTEXT.TYPE; - @state() - private _name = ''; + _groups: UserGroupResponseModel[] = []; - constructor() { - super(); - this.consumeContext(UMB_CURRENT_USER_CONTEXT, (instance) => { - this.#currentUserContext = instance; - this.#observeCurrentUser(); - }); + async clearToken() { + const authContext = await this.getContext(UMB_AUTH_CONTEXT); + authContext.clearTokenStorage(); } - #observeCurrentUser(): void { - if (!this.#currentUserContext) return; - this.observe(this.#currentUserContext.currentUser, (user) => { - this._name = user?.name ?? ''; - }); + async makeAuthorizedRequest() { + const { data } = await tryExecuteAndNotify(this, UserGroupResource.getUserGroup({ skip: 0, take: 10 })); + + if (data) { + this._groups = data.items; + } } render() { return html` -

- Welcome, ${this._name} -

-

- This is the beta version of Umbraco 14, where you can have a first-hand look at the new Backoffice. -

- Please refer to the - documentation to learn - more about what is possible. Here you will find excellent tutorials, guides, and references to help you get - started extending the Backoffice. + Clear all tokens + Make authorized request + + ${this._groups.map((group) => html`

${group.name}

`)}

`; } - - static styles = [ - UmbTextStyles, - css` - :host { - display: block; - padding: var(--uui-size-layout-1); - } - p { - position: relative; - } - `, - ]; } export default UmbUmbracoNewsDashboardElement;