@chat21/chat21-ionic 3.0.55 → 3.0.57

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # chat21-ionic ver 3.0
2
2
 
3
+ ### 3.0.57
4
+ - Review of the "login" code
5
+
6
+ ### 3.0.56
7
+ - Improves the auto-login method
8
+
3
9
  ### 3.0.55
4
10
  - Distributed release in production
5
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chat21/chat21-ionic",
3
- "version": "3.0.55",
3
+ "version": "3.0.57",
4
4
  "author": "Tiledesk SRL",
5
5
  "homepage": "https://ionicframework.com/",
6
6
  "scripts": {
@@ -58,6 +58,7 @@ import * as PACKAGE from 'package.json';
58
58
 
59
59
  import { Subject } from 'rxjs';
60
60
  import { filter, takeUntil } from 'rxjs/operators'
61
+
61
62
  // import { filter } from 'rxjs/operators';
62
63
 
63
64
  @Component({
@@ -73,7 +74,7 @@ export class AppComponent implements OnInit {
73
74
  // public appIsOnline$: Observable<boolean> = undefined;
74
75
  checkInternet: boolean;
75
76
 
76
- private subscription: Subscription;
77
+ private BSAuthStateChangedSubscriptionRef: Subscription;
77
78
  public sidebarPage: any;
78
79
  public notificationsEnabled: boolean;
79
80
  public zone: NgZone;
@@ -99,7 +100,7 @@ export class AppComponent implements OnInit {
99
100
  public executedInitializeAppByWatchConnection: boolean = false;
100
101
  private version: string;
101
102
  private unsubscribe$: Subject<any> = new Subject<any>();
102
- private isOnline: boolean = false;
103
+ // private isOnline: boolean = false;
103
104
 
104
105
  constructor(
105
106
  private platform: Platform,
@@ -162,71 +163,31 @@ export class AppComponent implements OnInit {
162
163
  this.logger.info('[APP-COMP] ngOnInit this.route.snapshot.params -->', this.route.snapshot.params);
163
164
  // this.initializeApp('oninit');
164
165
  const token = getParameterByName('jwt')
165
- this.logger.info('[APP-COMP] ngOnInit token get from params -->', token);
166
-
166
+ this.logger.info('[APP-COMP] ngOnInit AUTOLOGIN token get with getParameterByName -->', token);
167
+
167
168
  if (token) {
168
- this.isOnline = false;
169
- this.logger.log('[APP-COMP] AUTLOGIN > RUN SIGNINWITHCUSTOMTOKEN params ', token)
169
+ // this.isOnline = false;
170
+ // this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN token get with this.isOnline ', this.isOnline)
171
+ this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN token get with getParameterByName ', token)
170
172
  // save token in local storage then
171
- this.appStorageService.setItem('tiledeskToken', token);
173
+
174
+ const storedToken = this.appStorageService.getItem('tiledeskToken');
175
+ this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN storedToken ', storedToken)
176
+ this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN SAVE THE PARAMS TOKEN ', token)
177
+ if (storedToken !== token) {
178
+ this.appStorageService.setItem('tiledeskToken', token);
179
+ } else {
180
+ this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN the current user already exist DON\'T SAVE ')
181
+ }
172
182
  }
173
183
  this.initializeApp('oninit');
174
- // else {
175
- // this.isOnline = false;
176
- // this.logger.log('[APP-COMP] NO AUTLOGIN > RUN INIZIALIZE APP')
177
- // this.initializeApp('oninit');
178
- // }
179
-
180
- // const param = this.param();
181
- // const token: string = param.get("jwt");
182
- // this.logger.info('[APP-COMP] ngOnInit token geet from params -->', token);
183
-
184
- // this.subscription = this.router.events.subscribe((event) => {
185
- // if (event instanceof NavigationStart) {
186
- // const current_url = event.url
187
- // this.logger.info('[APP-COMP] - NavigationStart event current_url ', current_url);
188
- // if (current_url.includes('jwt')) {
189
- // this.logger.info('[APP-COMP] - NavigationStart event current_url INCLUDES jwt');
190
- // const tokenString = current_url.slice(current_url.lastIndexOf('=') + 1)
191
- // // const token = tokenString.substring(1, tokenString.length - 1)
192
- // const token = tokenString
193
- // this.logger.info('[APP-COMP] - NavigationStart event current_url INCLUDES jwt > token ', token);
194
- // this.signInWithCustomToken("JWT%20eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MDhhZDAyZDNhNGRjMDAwMzQ0YWRlMTciLCJlbWFpbCI6Im51b3ZvcHJlZ2lub0BtYWlsbmEuY28iLCJmaXJzdG5hbWUiOiJOdW92byIsImxhc3RuYW1lIjoiUHJlZ2lubyIsImVtYWlsdmVyaWZpZWQiOnRydWUsImlhdCI6MTYzNDE5OTU1NiwiYXVkIjoiaHR0cHM6Ly90aWxlZGVzay5jb20iLCJpc3MiOiJodHRwczovL3RpbGVkZXNrLmNvbSIsInN1YiI6InVzZXIiLCJqdGkiOiIwMGQyNTI0MS05MDI4LTRmYTYtYmJhNi0xOGNmZTUwNzdiYTMifQ.4kCuHOyceIMWnlyOiCvQEiDPqDZR8HwYgyQoqMYJxX0")
195
- // } else {
196
- // this.logger.info('[APP-COMP] - NavigationStart event current_url NOT INCLUDES jwt');
197
- // }
198
- // }
199
- // });
200
184
 
201
- // this.route.queryParams.subscribe(params => {
202
- // this.logger.log('[APP-COMP] ROUTE QUERY PARAMS params', params)
203
- // if (params.jwt) {
204
- // this.isOnline = false;
205
- // this.logger.log('[APP-COMP] AUTLOGIN > RUN SIGNINWITHCUSTOMTOKEN params ', params)
206
- // this.tiledeskAuthService.signInWithCustomToken(params.jwt).then(user => {
207
- // this.logger.log('[APP-COMP] AUTLOGIN > RUN SIGNINWITHCUSTOMTOKEN user', user)
208
- // // if (user) {
209
- // this.logger.log('[APP-COMP] AUTLOGIN > RUN INIZIALIZE APP')
210
- // this.initializeApp('oninit');
211
- // // }
212
- // this.messagingAuthService.createCustomToken(params.jwt)
213
- // }).catch(error => {
214
- // this.logger.error('[APP-COMP] AUTLOGIN > RUN SIGNINWITHCUSTOMTOKE - ERROR', error)
215
- // })
216
- // }
217
- // else {
218
- // this.isOnline = false;
219
- // this.logger.log('[APP-COMP] NO AUTLOGIN > RUN INIZIALIZE APP')
220
- // this.initializeApp('oninit');
221
- // }
222
- // });
223
185
  }
224
186
 
225
187
 
226
188
  signInWithCustomToken(token) {
227
-
228
- this.isOnline = false;
229
- this.logger.log('[APP-COMP] SIGNINWITHCUSTOMTOKEN AUTLOGIN token', token)
189
+ // this.isOnline = false;
190
+ this.logger.log('[APP-COMP] SIGNINWITHCUSTOMTOKEN token', token)
230
191
  this.tiledeskAuthService.signInWithCustomToken(token)
231
192
  .then((user: any) => {
232
193
  this.logger.log('[APP-COMP] SIGNINWITHCUSTOMTOKEN AUTLOGIN user', user)
@@ -242,8 +203,7 @@ export class AppComponent implements OnInit {
242
203
 
243
204
  /** */
244
205
  initializeApp(calledby: string) {
245
- this.logger.info('[APP-COMP] - initializeApp !!! CALLED-BY: ', calledby);
246
-
206
+ console.log('[APP-COMP] - X - initializeApp !!! CALLED-BY: ', calledby);
247
207
  this.logger.log('[APP-COMP] appconfig platform is cordova: ', this.platform.is('cordova'))
248
208
 
249
209
  if (!this.platform.is('cordova')) {
@@ -263,10 +223,6 @@ export class AppComponent implements OnInit {
263
223
 
264
224
  this.tenant = appconfig.firebaseConfig.tenant;
265
225
  this.logger.info('[APP-COMP] appconfig firebaseConfig tenant: ', this.tenant);
266
-
267
-
268
-
269
-
270
226
  this.notificationsEnabled = true;
271
227
  this.zone = new NgZone({}); // a cosa serve?
272
228
 
@@ -298,35 +254,19 @@ export class AppComponent implements OnInit {
298
254
 
299
255
  this.initAuthentication();
300
256
  this.initSubscriptions();
301
- this.initAudio()
257
+ this.initAudio();
302
258
 
303
259
  this.logger.debug('[APP-COMP] initializeApp:: ', this.sidebarNav, this.detailNav);
304
- // this.listenToLogoutEvent()
260
+
305
261
  this.translateToastMsgs();
306
262
 
307
263
  // ---------------------------------------
308
264
  // Watch to network status
309
265
  // ---------------------------------------
310
266
  this.watchToConnectionStatus();
311
- // this.listenToUserIsSignedIn();
312
-
313
-
314
267
  });
315
268
  }
316
269
 
317
- // listenToUserIsSignedIn() {
318
- // this.tiledeskAuthService.isOnline$
319
- // .pipe(filter((isOnline) => isOnline !== null))
320
- // .subscribe((isOnline: any) => {
321
- // console.log('[APP-COMP] user isOnline: ', isOnline);
322
-
323
- // // if (isOnline === false) {
324
- // // this.events.publish('profileInfoButtonClick:logout', true);
325
- // // }
326
- // });
327
- // }
328
-
329
-
330
270
 
331
271
  watchToConnectionStatus() {
332
272
  this.networkService.checkInternetFunc().subscribe(isOnline => {
@@ -352,7 +292,7 @@ export class AppComponent implements OnInit {
352
292
  if (elemIonNavchildNodes.length === 0) {
353
293
  this.logger.log('[APP-COMP] - watchToConnectionStatus - elemIonNavchildNodes HERE YES', elemIonNavchildNodes);
354
294
 
355
- this.initializeApp('checkinternet');
295
+ // this.initializeApp('checkinternet');
356
296
  this.executedInitializeAppByWatchConnection = true;
357
297
  }
358
298
  }, 2000);
@@ -366,7 +306,7 @@ export class AppComponent implements OnInit {
366
306
  const childElementCount = elemIonRouterOutlet.childElementCount;
367
307
  this.logger.log('[APP-COMP] - watchToConnectionStatus - mobile * childElementCount *', childElementCount)
368
308
  if (childElementCount === 1) {
369
- this.initializeApp('checkinternet');
309
+ // this.initializeApp('checkinternet');
370
310
  this.executedInitializeAppByWatchConnection = true;
371
311
  }
372
312
  }, 2000);
@@ -415,19 +355,18 @@ export class AppComponent implements OnInit {
415
355
  /**------- AUTHENTICATION FUNCTIONS --> START <--- +*/
416
356
  private initAuthentication() {
417
357
  const tiledeskToken = this.appStorageService.getItem('tiledeskToken')
418
- this.logger.log('[APP-COMP] >>> INIT-AUTHENTICATION !!! ')
358
+ console.log('[APP-COMP] >>> INIT-AUTHENTICATION !!! ')
419
359
  this.logger.log('[APP-COMP] >>> initAuthentication tiledeskToken ', tiledeskToken)
420
-
421
- const currentUser = JSON.parse(this.appStorageService.getItem('currentUser'));
422
- this.logger.log('[APP-COMP] >>> initAuthentication currentUser ', currentUser)
360
+ // const currentUser = JSON.parse(this.appStorageService.getItem('currentUser'));
361
+ // this.logger.log('[APP-COMP] >>> initAuthentication currentUser ', currentUser)
423
362
  if (tiledeskToken) {
424
363
  this.logger.log('[APP-COMP] >>> initAuthentication I LOG IN WITH A TOKEN EXISTING IN THE LOCAL STORAGE OR WITH A TOKEN PASSED IN THE URL PARAMETERS <<<')
425
-
426
364
  this.tiledeskAuthService.signInWithCustomToken(tiledeskToken).then(user => {
427
365
  this.logger.log('[APP-COMP] >>> initAuthentication user ', user)
428
366
  this.messagingAuthService.createCustomToken(tiledeskToken)
429
- }).catch(error => { this.logger.error('[APP-COMP] initAuthentication SIGNINWITHCUSTOMTOKEN error::' + error) })
430
-
367
+ }).catch(error => {
368
+ this.logger.error('[APP-COMP] initAuthentication SIGNINWITHCUSTOMTOKEN error::', error)
369
+ })
431
370
  } else {
432
371
  this.logger.warn('[APP-COMP] >>> I AM NOT LOGGED IN <<<')
433
372
  const that = this;
@@ -439,24 +378,11 @@ export class AppComponent implements OnInit {
439
378
  }
440
379
  }, 1000);
441
380
  }
442
-
443
- // this.route.queryParams.subscribe(params => {
444
- // this.logger.log('[APP-COMP] SIGNINWITHCUSTOMTOKEN AUTLOGIN params 1', params)
445
- // if (params.jwt) {
446
- // this.isOnline = false;
447
- // this.logger.log('[APP-COMP] SIGNINWITHCUSTOMTOKEN AUTLOGIN params 2', params)
448
- // this.tiledeskAuthService.signInWithCustomToken(params.jwt).then(user => {
449
- // this.messagingAuthService.createCustomToken(params.jwt)
450
- // }).catch(error => {
451
- // this.logger.error('[APP-COMP] SIGNINWITHCUSTOMTOKEN error::', error)
452
- // })
453
- // }
454
- // });
455
381
  }
456
382
 
457
- authenticate() {
383
+ checkTokenAndGoOffline() {
458
384
  let token = this.appStorageService.getItem('tiledeskToken');
459
- this.logger.info('[APP-COMP] ***** authenticate - stored token *****', token);
385
+ this.logger.info('[APP-COMP] ***** checkTokenAndGoOffline - stored token *****', token);
460
386
  if (!token) {
461
387
  this.goOffLine()
462
388
  }
@@ -470,15 +396,15 @@ export class AppComponent implements OnInit {
470
396
  * @param user
471
397
  */
472
398
  goOnLine = () => {
473
- this.isOnline = true;
474
- this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] - GO ONLINE isOnline ', this.isOnline);
399
+ // this.isOnline = true;
400
+ // this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] - GO-ONLINE isOnline ', this.isOnline);
475
401
 
476
402
 
477
403
  clearTimeout(this.timeModalLogin);
478
404
  const tiledeskToken = this.tiledeskAuthService.getTiledeskToken();
479
405
  const currentUser = this.tiledeskAuthService.getCurrentUser();
480
406
  // this.logger.printDebug('APP-COMP - goOnLine****', currentUser);
481
- this.logger.log('[APP-COMP] - goOnLine****', currentUser);
407
+ this.logger.log('[APP-COMP] - GO-ONLINE - currentUser ', currentUser);
482
408
  this.chatManager.setTiledeskToken(tiledeskToken);
483
409
  this.chatManager.setCurrentUser(currentUser);
484
410
  // ----------------------------------------------
@@ -509,8 +435,8 @@ export class AppComponent implements OnInit {
509
435
  }
510
436
 
511
437
  goOffLine = () => {
512
- this.logger.log('[APP-COMP] ************** goOffLine:', this.authModal);
513
- this.isOnline = false;
438
+ this.logger.log('[APP-COMP] ************** goOffLine authModal:', this.authModal);
439
+ // this.isOnline = false;
514
440
  // this.conversationsHandlerService.conversations = [];
515
441
 
516
442
  this.chatManager.setTiledeskToken(null);
@@ -671,20 +597,30 @@ export class AppComponent implements OnInit {
671
597
  this.logger.log('initialize FROM [APP-COMP] - initSubscriptions');
672
598
 
673
599
 
674
- this.messagingAuthService.BSAuthStateChanged
675
- .pipe(takeUntil(this.unsubscribe$))
600
+ // ---------------------------------------------------------------------------------------------------
601
+ // Protecting from multiple subsciptions due to multiple app initializations (call to initializeApp())
602
+ // Only one subscriber x application allowed
603
+ // ---------------------------------------------------------------------------------------------------
604
+ if (this.BSAuthStateChangedSubscriptionRef) {
605
+ this.logger.log('initialize FROM [APP-COMP] - BSAuthStateChanged ALREADY SUBSCRIBED');
606
+ return;
607
+ }
608
+
609
+ this.BSAuthStateChangedSubscriptionRef = this.messagingAuthService.BSAuthStateChanged
610
+ // .pipe(takeUntil(this.unsubscribe$))
676
611
  .pipe(filter((state) => state !== null))
677
612
  .subscribe((state: any) => {
678
- this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged state', state);
679
- this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged isOnline', this.isOnline);
613
+ console.log('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged state', state);
614
+ // this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged isOnline', this.isOnline);
680
615
  if (state && state === AUTH_STATE_ONLINE) {
681
- const user = this.tiledeskAuthService.getCurrentUser();
682
- if (this.isOnline === false) {
683
- this.goOnLine();
684
- }
616
+ // const user = this.tiledeskAuthService.getCurrentUser();
617
+ // if (this.isOnline === false) {
618
+ // if (AUTH_STATE_ONLINE) {
619
+ this.goOnLine();
620
+ // }
685
621
  } else if (state === AUTH_STATE_OFFLINE) {
686
- // that.goOffLine();
687
- this.authenticate() //se c'è un tiledeskToken salvato, allora aspetta, altrimenti vai offline
622
+ this.checkTokenAndGoOffline() //se c'è un tiledeskToken salvato, allora aspetta, altrimenti vai offline
623
+ // this.goOffLine()
688
624
  }
689
625
  }, error => {
690
626
  this.logger.error('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged * error * ', error)
@@ -922,20 +858,35 @@ export class AppComponent implements OnInit {
922
858
  }
923
859
 
924
860
  if (this.appStorageService.getItem('tiledeskToken') === null) {
925
- this.logger.log('[APP-COMP] - onStorageChanged tiledeskToken is null - RUN LOGOUT')
861
+ console.log('[APP-COMP] - onStorageChanged tiledeskToken is null - RUN LOGOUT')
926
862
  this.tiledeskAuthService.logOut()
927
863
  this.messagingAuthService.logout();
928
864
  this.events.publish('profileInfoButtonClick:logout', true);
929
- this.isOnline = false;
865
+ // this.isOnline = false;
930
866
  }
931
867
  else {
932
868
  const currentUser = this.tiledeskAuthService.getCurrentUser();
869
+ console.log('[APP-COMP] - X - onStorageChanged currentUser', currentUser)
870
+
871
+ const currentToken = this.tiledeskAuthService.getTiledeskToken();
872
+ console.log('[APP-COMP] - onStorageChanged currentToken', currentToken)
873
+ if (this.appStorageService.getItem('tiledeskToken') !== null && currentToken !== this.appStorageService.getItem('tiledeskToken')) {
874
+
875
+ console.log('[APP-COMP] - onStorageChanged wentOnline 2')
876
+ // DEALLOCO RISORSE OCCUPATE
877
+ this.messagingAuthService.logout();
878
+ this.appStorageService.removeItem('currentUser')
879
+ this.tiledeskAuthService.setCurrentUser(null);
880
+ // this.unsubscribe$.next();
881
+ // this.unsubscribe$.complete();
882
+ this.initializeApp('onstoragechanged');
933
883
 
934
- if (!currentUser && this.appStorageService.getItem('tiledeskToken') !== null) {
935
- this.logger.log('[APP-COMP] - onStorageChanged currentUser', currentUser)
936
- // console.log('[APP-COMP] - onStorageChanged wentOnline 2', this.wentOnline)
884
+ console.log('[APP-COMP] - that.BSAuthStateChanged ', this.messagingAuthService.BSAuthStateChanged)
937
885
 
938
- this.initializeApp('onstoragechanged');
886
+ // console.log('[APP-COMP] onAuthStateChanged HERE !!! ')
887
+ // firebase.auth().onAuthStateChanged(user => {
888
+ // console.log('[APP-COMP] onAuthStateChanged', user)
889
+ // })
939
890
 
940
891
  }
941
892
  }
@@ -9,8 +9,8 @@ export abstract class AppStorageService {
9
9
  abstract initialize(storagePrefix: string, persistence: string, projectID?: string): void;
10
10
  abstract getItem(key: string): any;
11
11
  abstract setItem(key: string, value: any): void;
12
- abstract getItemWithoutProjectID(key: string): any;
13
- abstract setItemWithoutProjectID(key: string, value: any): void;
12
+ // abstract getItemWithoutProjectID(key: string): any; // deprecated !Not tUsed
13
+ // abstract setItemWithoutProjectID(key: string, value: any): void; // deprecated !Not tUsed
14
14
  abstract removeItem(key: string): void;
15
15
  abstract clear(): void;
16
16
 
@@ -64,7 +64,7 @@ export class FirebaseArchivedConversationsHandler extends ArchivedConversationsH
64
64
  * inizializzo conversations handler
65
65
  */
66
66
  initialize(tenant: string, userId: string, translationMap: Map<string, string>) {
67
- this.logger.info('[initialize FROM [APP-COMP] - FIREBASEArchivedConversationsHandlerSERVICE] tenant ', tenant, ' - userId: ', userId, ' - translationMap: ', translationMap)
67
+ this.logger.info('initialize FROM [APP-COMP] - FIREBASEArchivedConversationsHandlerSERVICE] tenant ', tenant, ' - userId: ', userId, ' - translationMap: ', translationMap)
68
68
  this.tenant = tenant;
69
69
  this.loggedUserId = userId;
70
70
  this.translationMap = translationMap;
@@ -33,6 +33,7 @@ import { LoggerService } from '../abstract/logger.service';
33
33
  import { Observable, Observer, fromEvent, merge } from 'rxjs';
34
34
  import { map } from 'rxjs/operators'
35
35
  import { Network } from '@ionic-native/network/ngx';
36
+
36
37
  // @Injectable({ providedIn: 'root' })
37
38
  @Injectable()
38
39
  export class FirebaseAuthService extends MessagingAuthService {
@@ -60,40 +61,58 @@ export class FirebaseAuthService extends MessagingAuthService {
60
61
 
61
62
  status = 'ONLINE';
62
63
  isConnected = true;
63
-
64
+ unsubscribe: any;
64
65
  constructor(
65
66
  public http: HttpClient,
66
67
  private network: Network,
67
68
  private connectionService: ConnectionService
68
69
  ) {
69
70
  super();
71
+ // this.initialize()
70
72
  }
71
73
 
72
74
  /**
73
75
  *
74
76
  */
75
77
  initialize() {
76
-
78
+ console.log('initialize FROM [APP-COMP] [FIREBASEAuthSERVICE]')
77
79
  this.SERVER_BASE_URL = this.getBaseUrl();
78
80
  this.URL_TILEDESK_CREATE_CUSTOM_TOKEN = this.SERVER_BASE_URL + 'chat21/firebase/auth/createCustomToken';
79
81
  this.logger.info('[FIREBASEAuthSERVICE] - initialize URL_TILEDESK_CREATE_CUSTOM_TOKEN ', this.URL_TILEDESK_CREATE_CUSTOM_TOKEN)
80
- // this.URL_TILEDESK_SIGNIN = this.SERVER_BASE_URL + 'auth/signin';
81
- // this.URL_TILEDESK_SIGNIN_ANONYMOUSLY = this.SERVER_BASE_URL + 'auth/signinAnonymously'
82
- // this.URL_TILEDESK_SIGNIN_WITH_CUSTOM_TOKEN = this.SERVER_BASE_URL + 'auth/signinWithCustomToken';
83
- // this.checkIsAuth();
84
-
85
- // this.createOnline$().subscribe((isOnline) =>{
86
- // console.log('FIREBASEAuthSERVICE] isOnline ', isOnline);
87
- // if (isOnline === true ) {
88
- // this.onAuthStateChanged();
89
- // }
90
- // })
91
- // this.checkInternetConnection()
92
82
 
93
- this.onAuthStateChanged();
83
+
84
+ let firebasePersistence;
85
+ // console.log('FB-AUTH firebasePersistence', this.getPersistence())
86
+ switch (this.getPersistence()) {
87
+ case 'SESSION': {
88
+ firebasePersistence = firebase.auth.Auth.Persistence.SESSION;
89
+ break;
90
+ }
91
+ case 'LOCAL': {
92
+ firebasePersistence = firebase.auth.Auth.Persistence.LOCAL;
93
+ break;
94
+ }
95
+ case 'NONE': {
96
+ firebasePersistence = firebase.auth.Auth.Persistence.NONE;
97
+ break;
98
+ }
99
+ default: {
100
+ firebasePersistence = firebase.auth.Auth.Persistence.NONE;
101
+ break;
102
+ }
103
+ }
104
+ firebase.auth().setPersistence(firebasePersistence).then(async () => {
105
+ console.log('[FIREBASEAuthSERVICE] firebasePersistence ', firebasePersistence)
106
+ this.onAuthStateChanged();
107
+ })
108
+ .catch((error) => {
109
+ this.logger.error('[FIREBASEAuthSERVICE] signInFirebaseWithCustomToken Error: ', error);
110
+ });
111
+
112
+
94
113
  }
95
114
 
96
- checkInternetConnection () {
115
+ checkInternetConnection() {
97
116
  this.logger.log('[FIREBASEAuthSERVICE] - checkInternetConnection');
98
117
  // let connectSubscription = this.network.onConnect().subscribe(() => {
99
118
  // this.logger.log('[FIREBASEAuthSERVICE] - network connected!');
@@ -107,28 +126,28 @@ export class FirebaseAuthService extends MessagingAuthService {
107
126
  // }, 3000);
108
127
  // });
109
128
 
110
-
111
- this.connectionService.monitor().subscribe(isConnected => {
112
- this.isConnected = isConnected;
113
- this.logger.log('[FIREBASEAuthSERVICE] - checkInternetConnection isConnected', isConnected);
114
- if (this.isConnected) {
115
- this.status = "ONLINE";
116
-
117
- // this.onAuthStateChanged();
118
- firebase.auth().onAuthStateChanged(user => {
119
- this.logger.log('[FIREBASEAuthSERVICE] checkInternetConnection onAuthStateChanged', user)
120
- })
121
- }
122
- else {
123
- this.status = "OFFLINE";
124
- // this.onAuthStateChanged();
125
- firebase.auth().onAuthStateChanged(user => {
126
- this.logger.log('[FIREBASEAuthSERVICE] checkInternetConnection onAuthStateChanged', user)
127
- })
128
- }
129
- })
130
-
131
-
129
+
130
+ // this.connectionService.monitor().subscribe(isConnected => {
131
+ // this.isConnected = isConnected;
132
+ // this.logger.log('[FIREBASEAuthSERVICE] - checkInternetConnection isConnected', isConnected);
133
+ // if (this.isConnected) {
134
+ // this.status = "ONLINE";
135
+
136
+ // // this.onAuthStateChanged();
137
+ // firebase.auth().onAuthStateChanged(user => {
138
+ // this.logger.log('[FIREBASEAuthSERVICE] checkInternetConnection onAuthStateChanged', user)
139
+ // })
140
+ // }
141
+ // else {
142
+ // this.status = "OFFLINE";
143
+ // // this.onAuthStateChanged();
144
+ // firebase.auth().onAuthStateChanged(user => {
145
+ // this.logger.log('[FIREBASEAuthSERVICE] checkInternetConnection onAuthStateChanged', user)
146
+ // })
147
+ // }
148
+ // })
149
+
150
+
132
151
  }
133
152
 
134
153
  // createOnline$() {
@@ -178,19 +197,37 @@ export class FirebaseAuthService extends MessagingAuthService {
178
197
  */
179
198
  onAuthStateChanged() {
180
199
  const that = this;
181
- firebase.auth().onAuthStateChanged(user => {
182
- this.logger.log('initialize FROM [APP-COMP] - [FIREBASEAuthSERVICE] onAuthStateChanged', user)
200
+
201
+ // ---------------------------------------------------------------------------------------------------
202
+ // Protecting from multiple subsciptions due to multiple app initializations (call to initializeApp())
203
+ // Only one subscriber x application allowed
204
+ // ---------------------------------------------------------------------------------------------------
205
+ if (this.unsubscribe) {
206
+ console.log('initialize FROM [APP-COMP] - [FIREBASEAuthSERVICE] onAuthStateChanged ALREADY SUBSCRIBED')
207
+ return
208
+ }
209
+
210
+ this.unsubscribe = firebase.auth().onAuthStateChanged(user => {
211
+ console.log('initialize FROM [APP-COMP] - [FIREBASEAuthSERVICE] onAuthStateChanged', user)
183
212
  if (!user) {
184
213
  this.logger.log('[FIREBASEAuthSERVICE] 1 - PASSO OFFLINE AL CHAT MANAGER')
185
214
  // this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] - [FIREBASEAuthSERVICE] onAuthStateChanged user ', user)
186
-
215
+
187
216
  that.BSAuthStateChanged.next('offline');
217
+ // console.log('initialize FROM [APP-COMP] that.BSAuthStateChanged ', that.BSAuthStateChanged)
188
218
  } else {
189
219
  this.logger.log('[FIREBASEAuthSERVICE] 2 - PASSO ONLINE AL CHAT MANAGER')
190
220
  // this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] - [FIREBASEAuthSERVICE] onAuthStateChanged user ', user)
191
221
  that.BSAuthStateChanged.next('online');
192
222
  }
223
+ }, error => {
224
+ this.logger.error('initialize FROM [APP-COMP] - [FIREBASEAuthSERVICE] onAuthStateChanged * error * ', error)
225
+ }, () => {
226
+ this.logger.log('initialize FROM [APP-COMP] - [FIREBASEAuthSERVICE] onAuthStateChanged *** complete *** ');
227
+
193
228
  });
229
+
230
+
194
231
  }
195
232
 
196
233
  /**
@@ -198,37 +235,34 @@ export class FirebaseAuthService extends MessagingAuthService {
198
235
  * @param token
199
236
  */
200
237
  signInFirebaseWithCustomToken(token: string): Promise<any> {
201
- const that = this;
202
- let firebasePersistence;
203
- // console.log('FB-AUTH firebasePersistence', this.getPersistence())
204
- switch (this.getPersistence()) {
205
- case 'SESSION': {
206
- firebasePersistence = firebase.auth.Auth.Persistence.SESSION;
207
- break;
208
- }
209
- case 'LOCAL': {
210
- firebasePersistence = firebase.auth.Auth.Persistence.LOCAL;
211
- break;
212
- }
213
- case 'NONE': {
214
- firebasePersistence = firebase.auth.Auth.Persistence.NONE;
215
- break;
216
- }
217
- default: {
218
- firebasePersistence = firebase.auth.Auth.Persistence.NONE;
219
- break;
220
- }
221
- }
222
- return firebase.auth().setPersistence(firebasePersistence).then(async () => {
223
- return firebase.auth().signInWithCustomToken(token).then(async (user) => {
224
-
225
- // that.firebaseSignInWithCustomToken.next(response);
226
- }).catch((error) => {
227
- that.logger.error('[FIREBASEAuthSERVICE] signInFirebaseWithCustomToken Error: ', error);
228
- // that.firebaseSignInWithCustomToken.next(null);
229
- });
238
+ // const that = this;
239
+ // let firebasePersistence;
240
+ // // console.log('FB-AUTH firebasePersistence', this.getPersistence())
241
+ // switch (this.getPersistence()) {
242
+ // case 'SESSION': {
243
+ // firebasePersistence = firebase.auth.Auth.Persistence.SESSION;
244
+ // break;
245
+ // }
246
+ // case 'LOCAL': {
247
+ // firebasePersistence = firebase.auth.Auth.Persistence.LOCAL;
248
+ // break;
249
+ // }
250
+ // case 'NONE': {
251
+ // firebasePersistence = firebase.auth.Auth.Persistence.NONE;
252
+ // break;
253
+ // }
254
+ // default: {
255
+ // firebasePersistence = firebase.auth.Auth.Persistence.NONE;
256
+ // break;
257
+ // }
258
+ // }
259
+ // return firebase.auth().setPersistence(firebasePersistence).then(async () => {
260
+ return firebase.auth().signInWithCustomToken(token).then(async (user) => {
261
+
262
+ // that.firebaseSignInWithCustomToken.next(response);
230
263
  }).catch((error) => {
231
- that.logger.error('[FIREBASEAuthSERVICE] signInFirebaseWithCustomToken Error: ', error);
264
+ this.logger.error('[FIREBASEAuthSERVICE] signInFirebaseWithCustomToken Error: ', error);
265
+ // that.firebaseSignInWithCustomToken.next(null);
232
266
  });
233
267
  }
234
268
 
@@ -275,6 +309,8 @@ export class FirebaseAuthService extends MessagingAuthService {
275
309
  // cancello token
276
310
  // this.appStorage.removeItem('tiledeskToken');
277
311
  //localStorage.removeItem('firebaseToken');
312
+
313
+
278
314
  that.BSSignOut.next(true);
279
315
  }).catch((error) => {
280
316
  that.logger.error('[FIREBASEAuthSERVICE] signOut error: ', error);
@@ -322,9 +358,11 @@ export class FirebaseAuthService extends MessagingAuthService {
322
358
  logout() {
323
359
  this.logger.log('[FIREBASEAuthSERVICE] logout');
324
360
  this.BSAuthStateChanged.next(null);
361
+
325
362
  // cancello token firebase dal local storage e da firebase
326
363
  // dovrebbe scattare l'evento authchangeStat
327
364
  this.signOut();
365
+ // this.unsubscribe();
328
366
  }
329
367
 
330
368
  }
@@ -157,21 +157,16 @@ export class FirebaseNotifications extends NotificationsService {
157
157
 
158
158
  removeNotificationsInstance(callback: (string) => void) {
159
159
  var self = this;
160
- firebase.auth().onAuthStateChanged(function (user) {
161
-
162
- if (user) {
163
- self.logger.debug('[FIREBASE-NOTIFICATIONS] - FB User is signed in. ', user)
164
-
165
- self.logger.log('[FIREBASE-NOTIFICATIONS] >>>> removeNotificationsInstance > this.userId', self.userId);
166
- self.logger.log('[FIREBASE-NOTIFICATIONS] >>>> removeNotificationsInstance > FCMcurrentToken', self.FCMcurrentToken);
167
- // this.logger.log('[FIREBASE-NOTIFICATIONS] >>>> removeNotificationsInstance > this.tenant', this.tenant);
168
-
169
-
170
- } else {
171
- self.logger.debug('[FIREBASE-NOTIFICATIONS] - No FB user is signed in. ', user)
172
- }
173
- });
174
-
160
+ // firebase.auth().onAuthStateChanged(function (user) {
161
+ // if (user) {
162
+ // self.logger.debug('[FIREBASE-NOTIFICATIONS] - FB User is signed in. ', user)
163
+ // self.logger.log('[FIREBASE-NOTIFICATIONS] >>>> removeNotificationsInstance > this.userId', self.userId);
164
+ // self.logger.log('[FIREBASE-NOTIFICATIONS] >>>> removeNotificationsInstance > FCMcurrentToken', self.FCMcurrentToken);
165
+ // // this.logger.log('[FIREBASE-NOTIFICATIONS] >>>> removeNotificationsInstance > this.tenant', this.tenant);
166
+ // } else {
167
+ // self.logger.debug('[FIREBASE-NOTIFICATIONS] - No FB user is signed in. ', user)
168
+ // }
169
+ // });
175
170
  const urlNodeFirebase = '/apps/' + self.tenant
176
171
  const connectionsRefinstancesId = urlNodeFirebase + '/users/' + self.userId + '/instances/'
177
172
  self.logger.log('[FIREBASE-NOTIFICATIONS] >>>> connectionsRefinstancesId ', connectionsRefinstancesId);
@@ -194,7 +189,6 @@ export class FirebaseNotifications extends NotificationsService {
194
189
  })
195
190
  }
196
191
 
197
-
198
192
  }
199
193
 
200
194
  // removeNotificationsInstance() {
@@ -6,35 +6,35 @@ import { LoggerService } from './abstract/logger.service';
6
6
  import { LoggerInstance } from './logger/loggerInstance';
7
7
 
8
8
  @Injectable()
9
- export class LocalSessionStorage extends AppStorageService{
10
-
11
- private storagePrefix: string = STORAGE_PREFIX;
12
- private projectID: string;
13
- private persistence: string;
14
- private logger: LoggerService = LoggerInstance.getInstance();
15
-
16
- initialize(storagePrefix: string, persistence: string, projectID: string): void {
17
- this.storagePrefix = storagePrefix;
18
- this.projectID = projectID;
19
- this.persistence = persistence;
20
- // this.persistence = 'LOCAL';
21
- // this.logger.info('[LocalSessionStorage] - initialize ', this.storagePrefix, this.persistence, this.projectID)
9
+ export class LocalSessionStorage extends AppStorageService {
10
+
11
+ private storagePrefix: string = STORAGE_PREFIX;
12
+ private projectID: string;
13
+ private persistence: string;
14
+ private logger: LoggerService = LoggerInstance.getInstance();
15
+
16
+ initialize(storagePrefix: string, persistence: string, projectID: string): void {
17
+ this.storagePrefix = storagePrefix;
18
+ this.projectID = projectID;
19
+ this.persistence = persistence;
20
+ // this.persistence = 'LOCAL';
21
+ // this.logger.info('[LocalSessionStorage] - initialize ', this.storagePrefix, this.persistence, this.projectID)
22
22
  }
23
23
 
24
24
  /** GET item in local/session storage from key value
25
25
  * @param key
26
26
  */
27
27
  getItem(key: string) {
28
- let prefix;
29
- try {
30
- // const sv = 'sv' + environment.shemaVersion + '_';
31
- // prefix = prefix + sv;
32
- prefix = this.storagePrefix + '_';
33
- } catch (e) {
34
- this.logger.error('[LocalSessionStorage] getItem - Error :' + e);
35
- }
36
- const newKey = prefix + this.projectID + '_' + key;
37
- return this.getValueForKey(newKey);
28
+ let prefix;
29
+ try {
30
+ // const sv = 'sv' + environment.shemaVersion + '_';
31
+ // prefix = prefix + sv;
32
+ prefix = this.storagePrefix + '_';
33
+ } catch (e) {
34
+ this.logger.error('[LocalSessionStorage] getItem - Error :' + e);
35
+ }
36
+ const newKey = prefix + this.projectID + '_' + key;
37
+ return this.getValueForKey(newKey);
38
38
  }
39
39
 
40
40
  /** SET new item in local/session storage
@@ -42,173 +42,174 @@ export class LocalSessionStorage extends AppStorageService{
42
42
  * @param value
43
43
  */
44
44
  setItem(key: string, value: any): void {
45
- this.removeItem(key);
46
- let prefix;
47
- try {
48
- // const sv = 'sv' + environment.shemaVersion + '_';
49
- // prefix = prefix + sv;
50
- prefix = this.storagePrefix + '_';
51
- } catch (e) {
52
- this.logger.error('[LocalSessionStorage] setItem > Error :' + e);
53
- }
54
- const newKey = prefix + this.projectID + '_' + key;
55
- this.saveValueForKey(newKey, value);
45
+ // this.removeItem(key);
46
+ let prefix;
47
+ try {
48
+ // const sv = 'sv' + environment.shemaVersion + '_';
49
+ // prefix = prefix + sv;
50
+ prefix = this.storagePrefix + '_';
51
+ } catch (e) {
52
+ this.logger.error('[LocalSessionStorage] setItem > Error :' + e);
53
+ }
54
+ const newKey = prefix + this.projectID + '_' + key;
55
+ this.saveValueForKey(newKey, value);
56
56
  }
57
57
 
58
58
  /** GET item in local/session storage from key value without project id SUFFIX
59
- * @param key
59
+ * @param key
60
+ * @deprecated
60
61
  */
61
- getItemWithoutProjectID(key: string) {
62
- let prefix;
63
- try {
64
- // const sv = 'sv' + environment.shemaVersion + '_';
65
- // prefix = prefix + sv;
66
- prefix = this.storagePrefix + '_';
67
- } catch (e) {
68
- this.logger.error('[LocalSessionStorage] getItemWithoutProjectID > Error :' + e);
69
- }
70
- const newKey = prefix + key;
71
- return this.getValueForKey(newKey);
72
- }
62
+ // getItemWithoutProjectID(key: string) {
63
+ // let prefix;
64
+ // try {
65
+ // // const sv = 'sv' + environment.shemaVersion + '_';
66
+ // // prefix = prefix + sv;
67
+ // prefix = this.storagePrefix + '_';
68
+ // } catch (e) {
69
+ // this.logger.error('[LocalSessionStorage] getItemWithoutProjectID > Error :' + e);
70
+ // }
71
+ // const newKey = prefix + key;
72
+ // return this.getValueForKey(newKey);
73
+ // }
73
74
 
74
75
  /** SET new item in local/session storage without project id SUFFIX
75
76
  * @param key
76
77
  * @param value
77
78
  */
78
- setItemWithoutProjectID(key: string, value: any): void {
79
- this.removeItem(key);
80
- let prefix = STORAGE_PREFIX;
81
- try {
82
- // const sv = 'sv' + environment.shemaVersion + '_';
83
- // prefix = prefix + sv;
84
- prefix = this.storagePrefix + '_';
85
- } catch (e) {
86
- this.logger.error('[LocalSessionStorage] setItemWithoutProjectID > Error :' + e);
87
- }
88
- const newKey = prefix + key;
89
- this.saveValueForKey(newKey, value);
90
- }
79
+ // setItemWithoutProjectID(key: string, value: any): void {
80
+ // this.removeItem(key);
81
+ // let prefix = STORAGE_PREFIX;
82
+ // try {
83
+ // // const sv = 'sv' + environment.shemaVersion + '_';
84
+ // // prefix = prefix + sv;
85
+ // prefix = this.storagePrefix + '_';
86
+ // } catch (e) {
87
+ // this.logger.error('[LocalSessionStorage] setItemWithoutProjectID > Error :' + e);
88
+ // }
89
+ // const newKey = prefix + key;
90
+ // this.saveValueForKey(newKey, value);
91
+ // }
91
92
 
92
93
  removeItem(key: string): void {
93
- let prefix;
94
- try {
95
- // const sv = 'sv' + environment.shemaVersion + '_';
96
- // prefix = prefix + sv;
97
- prefix = this.storagePrefix + '_';
98
- } catch (e) {
99
- this.logger.error('[LocalSessionStorage] removeItem > Error :' + e);
100
- }
101
- const newKey = prefix + this.projectID + '_' + key;
102
- return this.removeItemForKey(newKey);
94
+ let prefix;
95
+ try {
96
+ // const sv = 'sv' + environment.shemaVersion + '_';
97
+ // prefix = prefix + sv;
98
+ prefix = this.storagePrefix + '_';
99
+ } catch (e) {
100
+ this.logger.error('[LocalSessionStorage] removeItem > Error :' + e);
101
+ }
102
+ const newKey = prefix + this.projectID + '_' + key;
103
+ return this.removeItemForKey(newKey);
103
104
  }
104
105
 
105
106
  clear(): void {
106
- let prefix;
107
- try {
108
- // const sv = 'sv' + environment.shemaVersion + '_';
109
- // prefix = prefix + sv;
110
- prefix = this.storagePrefix + '_';
111
- } catch (e) {
112
- this.logger.error('[LocalSessionStorage] clear > Error :' + e);
113
- }
114
- const prefixKey = prefix + this.projectID
115
- const arrayKey: Array<string> = [];
116
- for (let i = 0; i < localStorage.length; i++) {
117
- const key = localStorage.key(i);
118
- if (key.indexOf(prefixKey) !== -1) {
119
- arrayKey.push(key);
120
- }
121
- }
122
-
123
- for (let i = 0; i < arrayKey.length; i++) {
124
- // localStorage.removeItem(arrayKey[i]);
125
- this.removeItemForKey(arrayKey[i]);
107
+ let prefix;
108
+ try {
109
+ // const sv = 'sv' + environment.shemaVersion + '_';
110
+ // prefix = prefix + sv;
111
+ prefix = this.storagePrefix + '_';
112
+ } catch (e) {
113
+ this.logger.error('[LocalSessionStorage] clear > Error :' + e);
114
+ }
115
+ const prefixKey = prefix + this.projectID
116
+ const arrayKey: Array<string> = [];
117
+ for (let i = 0; i < localStorage.length; i++) {
118
+ const key = localStorage.key(i);
119
+ if (key.indexOf(prefixKey) !== -1) {
120
+ arrayKey.push(key);
126
121
  }
127
-
122
+ }
123
+
124
+ for (let i = 0; i < arrayKey.length; i++) {
125
+ // localStorage.removeItem(arrayKey[i]);
126
+ this.removeItemForKey(arrayKey[i]);
127
+ }
128
+
128
129
  }
129
130
 
130
131
 
131
132
  // ---------- PRIVATE METHODS start --------------- //
132
133
 
133
134
  private getValueForKey(key) {
134
- if (this.persistence === 'local' || this.persistence === 'LOCAL') {
135
- if (supports_html5_storage()) {
136
- return localStorage.getItem(key);
137
- } else {
138
- this.logger.warn('localStorage is not defind. Storage disabled');
139
- return null;
140
- }
141
- } else if (this.persistence === 'session' || this.persistence === 'SESSION') {
142
- if (supports_html5_session()) {
143
- return sessionStorage.getItem(key);
144
- } else {
145
- this.logger.warn('sessionStorage is not defind. Storage disabled');
146
- return null;
147
- }
148
- } else if (this.persistence === 'none' || this.persistence === 'NONE') {
135
+ if (this.persistence === 'local' || this.persistence === 'LOCAL') {
136
+ if (supports_html5_storage()) {
137
+ return localStorage.getItem(key);
138
+ } else {
139
+ this.logger.warn('localStorage is not defind. Storage disabled');
140
+ return null;
141
+ }
142
+ } else if (this.persistence === 'session' || this.persistence === 'SESSION') {
143
+ if (supports_html5_session()) {
144
+ return sessionStorage.getItem(key);
145
+ } else {
146
+ this.logger.warn('sessionStorage is not defind. Storage disabled');
149
147
  return null;
148
+ }
149
+ } else if (this.persistence === 'none' || this.persistence === 'NONE') {
150
+ return null;
151
+ } else {
152
+ if (supports_html5_storage()) {
153
+ return localStorage.getItem(key);
150
154
  } else {
151
- if (supports_html5_storage()) {
152
- return localStorage.getItem(key);
153
- } else {
154
- this.logger.warn('localStorage is not defind. Storage disabled');
155
- return null;
156
- }
155
+ this.logger.warn('localStorage is not defind. Storage disabled');
156
+ return null;
157
157
  }
158
+ }
158
159
  }
159
160
 
160
161
  private saveValueForKey(key, value) {
161
- if (this.persistence === 'local' || this.persistence === 'LOCAL') {
162
- if (supports_html5_storage()) {
163
- return localStorage.setItem(key, value);
164
- } else {
165
- this.logger.warn('localStorage is not defind. Storage disabled');
166
- return null;
167
- }
168
- } else if (this.persistence === 'session' || this.persistence === 'SESSION') {
169
- if (supports_html5_session()) {
170
- return sessionStorage.setItem(key, value);
171
- } else {
172
- this.logger.warn('sessionStorage is not defind. Storage disabled');
173
- return null;
174
- }
175
- } else if (this.persistence === 'none' || this.persistence === 'NONE') {
162
+ if (this.persistence === 'local' || this.persistence === 'LOCAL') {
163
+ if (supports_html5_storage()) {
164
+ return localStorage.setItem(key, value);
165
+ } else {
166
+ this.logger.warn('localStorage is not defined. Storage disabled');
167
+ return null;
168
+ }
169
+ } else if (this.persistence === 'session' || this.persistence === 'SESSION') {
170
+ if (supports_html5_session()) {
171
+ return sessionStorage.setItem(key, value);
172
+ } else {
173
+ this.logger.warn('sessionStorage is not defined. Storage disabled');
176
174
  return null;
175
+ }
176
+ } else if (this.persistence === 'none' || this.persistence === 'NONE') {
177
+ return null;
178
+ } else {
179
+ if (supports_html5_storage()) {
180
+ return localStorage.setItem(key, value);
177
181
  } else {
178
- if (supports_html5_storage()) {
179
- return localStorage.setItem(key, value);
180
- } else {
181
- this.logger.warn('localStorage is not defind. Storage disabled');
182
- return null;
183
- }
182
+ this.logger.warn('localStorage is not defined. Storage disabled');
183
+ return null;
184
184
  }
185
+ }
185
186
  }
186
187
 
187
188
  private removeItemForKey(key: string) {
188
- if (this.persistence === 'local' || this.persistence === 'LOCAL') {
189
- if (supports_html5_storage()) {
190
- return localStorage.removeItem(key);
191
- } else {
192
- this.logger.warn('localStorage is not defind. Storage disabled');
193
- return null;
194
- }
195
- } else if (this.persistence === 'session' || this.persistence === 'SESSION') {
196
- if (supports_html5_session()) {
197
- return sessionStorage.removeItem(key);
198
- } else {
199
- this.logger.warn('sessionStorage is not defind. Storage disabled');
200
- return null;
201
- }
202
- } else if (this.persistence === 'none' || this.persistence === 'NONE') {
189
+ if (this.persistence === 'local' || this.persistence === 'LOCAL') {
190
+ if (supports_html5_storage()) {
191
+ return localStorage.removeItem(key);
192
+ } else {
193
+ this.logger.warn('localStorage is not defind. Storage disabled');
194
+ return null;
195
+ }
196
+ } else if (this.persistence === 'session' || this.persistence === 'SESSION') {
197
+ if (supports_html5_session()) {
198
+ return sessionStorage.removeItem(key);
199
+ } else {
200
+ this.logger.warn('sessionStorage is not defind. Storage disabled');
203
201
  return null;
202
+ }
203
+ } else if (this.persistence === 'none' || this.persistence === 'NONE') {
204
+ return null;
205
+ } else {
206
+ if (supports_html5_storage()) {
207
+ return localStorage.removeItem(key);
204
208
  } else {
205
- if (supports_html5_storage()) {
206
- return localStorage.removeItem(key);
207
- } else {
208
- this.logger.warn('localStorage is not defind. Storage disabled');
209
- return null;
210
- }
209
+ this.logger.warn('localStorage is not defind. Storage disabled');
210
+ return null;
211
211
  }
212
+ }
212
213
  }
213
214
 
214
215
  }