@umbraco-cms/backoffice 18.2.0-rc → 18.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,13 +5,16 @@ import { HubConnectionBuilder, HttpTransportType } from '../../../external/signa
5
5
  import { UmbBooleanState, UmbStringState } from '../../../libs/observable-api/index.js';
6
6
  import { UmbContextBase } from '../../../libs/class-api/index.js';
7
7
  import { UmbLocalizationController } from '../../../libs/localization-api/index.js';
8
+ import { UMB_AUTH_CONTEXT } from '../../core/auth/index.js';
8
9
  import { UMB_NOTIFICATION_CONTEXT } from '../../core/notification/index.js';
9
10
  import { UMB_SERVER_CONTEXT } from '../../core/server/index.js';
10
11
  export class UmbPreviewContext extends UmbContextBase {
12
+ #authContext;
11
13
  #connection;
12
14
  #currentArgs;
13
15
  #notificationContext;
14
16
  #resizeController;
17
+ #serverContext;
15
18
  #serverUrl;
16
19
  #previewRepository;
17
20
  #localize;
@@ -53,8 +56,13 @@ export class UmbPreviewContext extends UmbContextBase {
53
56
  return;
54
57
  }
55
58
  this.#serverUrl = serverUrl;
59
+ this.#serverContext = serverContext;
56
60
  this.#setPreviewUrl({ serverUrl });
57
- this.#initHubConnection(serverUrl, serverContext);
61
+ this.#initHubConnection();
62
+ });
63
+ this.consumeContext(UMB_AUTH_CONTEXT, (authContext) => {
64
+ this.#authContext = authContext;
65
+ this.#initHubConnection();
58
66
  });
59
67
  this.consumeContext(UMB_NOTIFICATION_CONTEXT, (notificationContext) => {
60
68
  this.#notificationContext = notificationContext;
@@ -70,15 +78,20 @@ export class UmbPreviewContext extends UmbContextBase {
70
78
  this.#connection = undefined;
71
79
  }
72
80
  }
73
- async #initHubConnection(serverUrl, serverContext) {
74
- const previewHubUrl = `${serverUrl}/umbraco/PreviewHub`;
81
+ async #initHubConnection() {
82
+ const authContext = this.#authContext;
83
+ if (!authContext || !this.#serverUrl)
84
+ return;
85
+ const previewHubUrl = `${this.#serverUrl}/umbraco/PreviewHub`;
75
86
  // Make sure that no previous connection exists.
76
87
  if (this.#connection) {
77
88
  await this.#connection.stop();
78
89
  this.#connection = undefined;
79
90
  }
80
- const skipNegotiation = serverContext?.getServerConnection()?.getSignalRSkipNegotiation() ?? false;
81
- const hubOptions = {};
91
+ const skipNegotiation = this.#serverContext?.getServerConnection()?.getSignalRSkipNegotiation() ?? false;
92
+ const hubOptions = {
93
+ accessTokenFactory: () => authContext.getLatestToken(),
94
+ };
82
95
  if (skipNegotiation) {
83
96
  hubOptions.skipNegotiation = true;
84
97
  hubOptions.transport = HttpTransportType.WebSockets;