@@ -57,26 +57,6 @@ export class Auth
57
57
appName : app . name
58
58
} ) ;
59
59
60
- let persistences : exp . Persistence [ ] = [ exp . inMemoryPersistence ] ;
61
-
62
- // Only deal with persistences in web environments
63
- if ( typeof window !== 'undefined' ) {
64
- // Note this is slightly different behavior: in this case, the stored
65
- // persistence is checked *first* rather than last. This is because we want
66
- // to prefer stored persistence type in the hierarchy.
67
- persistences = _getPersistencesFromRedirect ( apiKey , app . name ) ;
68
-
69
- for ( const persistence of [
70
- exp . indexedDBLocalPersistence ,
71
- exp . browserLocalPersistence ,
72
- exp . browserSessionPersistence
73
- ] ) {
74
- if ( ! persistences . includes ( persistence ) ) {
75
- persistences . push ( persistence ) ;
76
- }
77
- }
78
- }
79
-
80
60
// TODO: platform needs to be determined using heuristics
81
61
_assert ( apiKey , exp . AuthErrorCode . INVALID_API_KEY , {
82
62
appName : app . name
@@ -87,7 +67,7 @@ export class Auth
87
67
typeof window !== 'undefined' ? CompatPopupRedirectResolver : undefined ;
88
68
this . _delegate = provider . initialize ( {
89
69
options : {
90
- persistence : persistences ,
70
+ persistence : buildPersistenceHierarchy ( apiKey , app . name ) ,
91
71
popupRedirectResolver : resolver
92
72
}
93
73
} ) as exp . AuthImpl ;
@@ -382,3 +362,41 @@ function wrapObservers(
382
362
complete
383
363
} ;
384
364
}
365
+
366
+ function buildPersistenceHierarchy (
367
+ apiKey : string ,
368
+ appName : string
369
+ ) : exp . Persistence [ ] {
370
+ // Note this is slightly different behavior: in this case, the stored
371
+ // persistence is checked *first* rather than last. This is because we want
372
+ // to prefer stored persistence type in the hierarchy. This is an empty
373
+ // array if window is not available or there is no pending redirect
374
+ const persistences = _getPersistencesFromRedirect ( apiKey , appName ) ;
375
+
376
+ // If "self" is available, add indexedDB
377
+ if (
378
+ typeof self !== 'undefined' &&
379
+ ! persistences . includes ( exp . indexedDBLocalPersistence )
380
+ ) {
381
+ persistences . push ( exp . indexedDBLocalPersistence ) ;
382
+ }
383
+
384
+ // If "window" is available, add HTML Storage persistences
385
+ if ( typeof window !== 'undefined' ) {
386
+ for ( const persistence of [
387
+ exp . browserLocalPersistence ,
388
+ exp . browserSessionPersistence
389
+ ] ) {
390
+ if ( ! persistences . includes ( persistence ) ) {
391
+ persistences . push ( persistence ) ;
392
+ }
393
+ }
394
+ }
395
+
396
+ // Add in-memory as a final fallback
397
+ if ( ! persistences . includes ( exp . inMemoryPersistence ) ) {
398
+ persistences . push ( exp . inMemoryPersistence ) ;
399
+ }
400
+
401
+ return persistences ;
402
+ }
0 commit comments