@lenne.tech/ng-base 0.3.8 → 0.3.11

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.
@@ -190,8 +190,11 @@ class AuthService {
190
190
  return this._token.value;
191
191
  }
192
192
  set token(token) {
193
+ var _a, _b;
193
194
  this._token.next(token);
194
195
  this.storageService.save('token', token);
196
+ (_a = this.subscriptionClient) === null || _a === void 0 ? void 0 : _a.close();
197
+ (_b = this.subscriptionClient) === null || _b === void 0 ? void 0 : _b.connect();
195
198
  }
196
199
  get tokenObservable() {
197
200
  return this._token.asObservable();
@@ -229,27 +232,17 @@ function apolloOptionsFactory(baseModuleConfig, httpLink, authService) {
229
232
  return forward(operation);
230
233
  });
231
234
  if (baseModuleConfig.wsUrl) {
232
- let wsClient;
233
- if (localStorage) {
234
- const token = authService.token || null;
235
- wsClient = new WebSocketLink({
236
- uri: baseModuleConfig.wsUrl,
237
- options: {
238
- reconnect: true,
239
- connectionParams: {
240
- authToken: token,
241
- },
242
- },
243
- });
244
- }
245
- else {
246
- wsClient = new WebSocketLink({
247
- uri: baseModuleConfig.wsUrl,
248
- options: {
249
- reconnect: true,
250
- },
251
- });
252
- }
235
+ const wsLink = new WebSocketLink({
236
+ uri: baseModuleConfig.wsUrl,
237
+ options: {
238
+ reconnect: true,
239
+ connectionParams: () => ({
240
+ Authorization: authService.token ? 'Bearer ' + authService.token : undefined,
241
+ }),
242
+ },
243
+ });
244
+ // Set client for reconnection on logout/login
245
+ authService.subscriptionClient = wsLink.subscriptionClient;
253
246
  // using the ability to split links, you can send data to each link
254
247
  // depending on what kind of operation is being sent
255
248
  links.push(split(
@@ -258,7 +251,7 @@ function apolloOptionsFactory(baseModuleConfig, httpLink, authService) {
258
251
  // @ts-ignore
259
252
  const { kind, operation } = getMainDefinition(query);
260
253
  return kind === 'OperationDefinition' && operation === 'subscription';
261
- }, wsClient, concat(authMiddleware, http)));
254
+ }, wsLink, concat(authMiddleware, http)));
262
255
  }
263
256
  else {
264
257
  links.push(http);