@@ -5,7 +5,7 @@ import throttle from 'lodash/throttle';
5
5
const settings = window . SETTINGS ;
6
6
const accountsUrl = `${ settings . accountHref } /api/user?always_200=true` ;
7
7
8
- function cached ( fn ) {
8
+ function cached ( fn , invalidateFn ) {
9
9
let valid = false ;
10
10
let cachedResult = null ;
11
11
const cachedFn = function ( ) {
@@ -17,6 +17,7 @@ function cached(fn) {
17
17
} ;
18
18
19
19
cachedFn . invalidate = ( ) => {
20
+ invalidateFn ( ) ;
20
21
valid = false ;
21
22
} ;
22
23
return cachedFn ;
@@ -64,26 +65,26 @@ const accountsModel = {
64
65
// ]
65
66
// });
66
67
67
- window . _OX_USER_PROMISE ||= fetch ( '/accounts/api/user?always_200=true' , { credentials : 'include' } ) . then (
68
- ( response ) => {
69
- if ( response . status === 200 ) {
70
- return response . json ( ) . catch ( ( error ) => {
71
- throw new Error ( `Failed to parse user JSON: ${ error . message } ` ) ;
72
- } ) ;
73
- } else {
74
- throw new Error ( `Failed to load user: HTTP ${ response . status } status code` ) ;
68
+ window . _OX_USER_PROMISE ||= fetch ( accountsUrl , { credentials : 'include' } ) . then (
69
+ ( response ) => {
70
+ if ( response . status === 200 ) {
71
+ return response . json ( ) . catch ( ( error ) => {
72
+ throw new Error ( `Failed to parse user JSON: ${ error . message } ` ) ;
73
+ } ) ;
74
+ } else {
75
+ throw new Error ( `Failed to load user: HTTP ${ response . status } status code` ) ;
76
+ }
75
77
}
76
- }
77
78
) ;
78
79
return window . _OX_USER_PROMISE . then ( ( user ) => {
79
- if ( window . dataLayer ) {
80
- window . dataLayer . push ( {
81
- faculty_status : user . faculty_status
82
- } ) ;
83
- }
84
- return user ;
80
+ if ( window . dataLayer ) {
81
+ window . dataLayer . push ( {
82
+ faculty_status : user . faculty_status
83
+ } ) ;
84
+ }
85
+ return user ;
85
86
} ) ;
86
- } )
87
+ } , ( ) => { window . _OX_USER_PROMISE = undefined ; } )
87
88
} ;
88
89
89
90
// eslint-disable-next-line complexity
@@ -157,7 +158,6 @@ const userModel = {
157
158
158
159
const throttledLoginCheck = throttle ( ( setData ) => {
159
160
accountsModel . load ( ) . then ( ( oldUser ) => {
160
- window . _OX_USER_PROMISE = undefined ;
161
161
accountsModel . load . invalidate ( ) ;
162
162
accountsModel . load ( ) . then ( ( newUser ) => {
163
163
if ( ! isEqual ( oldUser , newUser ) ) {
0 commit comments