@cortezaproject/corteza-vue 2022.3.1 → 2022.3.2-rc.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.
package/dist/index.es.js CHANGED
@@ -2006,8 +2006,6 @@ class Auth {
2006
2006
  return __awaiter(this, void 0, void 0, function* () {
2007
2007
  this.log.info('handling authentication');
2008
2008
  // State management
2009
- // - duplication checking
2010
- // - management handlers
2011
2009
  const dup = this.handleStateManagement();
2012
2010
  if (dup) {
2013
2011
  this.log.debug('duplicate tab: unauthorized');
@@ -2044,14 +2042,25 @@ class Auth {
2044
2042
  handleStateManagement() {
2045
2043
  // See if this is a duplicate
2046
2044
  const dup = this.sessionStorage.getItem(storeKeyFinalState) !== null;
2047
- // Bind listeners to cleanup
2048
- this.registerEventListener('beforeunload', function () {
2049
- this.sessionStorage.removeItem(storeKeyFinalState);
2050
- });
2051
- // Set state
2052
- this.sessionStorage.setItem(storeKeyFinalState, Date.now().toString());
2045
+ window.sessionStorage.setItem(storeKeyFinalState, Date.now().toString());
2053
2046
  return dup;
2054
2047
  }
2048
+ bindListeners() {
2049
+ // binding multiple listeners for cases where some browser refuser
2050
+ // to emit one of them.
2051
+ this.registerEventListener('pagehide', () => {
2052
+ this.cleanFlags();
2053
+ });
2054
+ this.registerEventListener('unload', () => {
2055
+ this.cleanFlags();
2056
+ });
2057
+ this.registerEventListener('beforeunload', () => {
2058
+ this.cleanFlags();
2059
+ });
2060
+ }
2061
+ cleanFlags() {
2062
+ this.sessionStorage.removeItem(storeKeyFinalState);
2063
+ }
2055
2064
  /**
2056
2065
  * Called when refresh token is re-fetched.
2057
2066
  *
@@ -2097,6 +2106,7 @@ class Auth {
2097
2106
  this.log.info('authorization code received', code);
2098
2107
  const rsp = yield this.exchangeCode(code);
2099
2108
  this.log.info('redirecting back to final destination', finalLocation);
2109
+ this.cleanFlags();
2100
2110
  this.location.assign(finalLocation);
2101
2111
  return rsp;
2102
2112
  });
@@ -2132,6 +2142,7 @@ class Auth {
2132
2142
  authUser.meta.preferredLanguage = data.preferred_language || 'en';
2133
2143
  }
2134
2144
  this[user] = authUser;
2145
+ this.bindListeners();
2135
2146
  return data;
2136
2147
  }).catch((error) => {
2137
2148
  this.log.error('data fetch form info endpoint failed', { oauth2InfoURL, headers, error });
@@ -2154,7 +2165,11 @@ class Auth {
2154
2165
  * Refresh token found in the storage,
2155
2166
  * let's use it to get new access token
2156
2167
  */
2157
- return this.exchangeRefresh(refreshToken);
2168
+ return this.exchangeRefresh(refreshToken)
2169
+ .then(r => {
2170
+ this.bindListeners();
2171
+ return r;
2172
+ });
2158
2173
  }
2159
2174
  throw new Error('Unauthenticated');
2160
2175
  });
@@ -2174,6 +2189,7 @@ class Auth {
2174
2189
  */
2175
2190
  startAuthenticationFlow() {
2176
2191
  this.log.debug('starting new authentication flow');
2192
+ this.cleanFlags();
2177
2193
  this.incFlowCounter();
2178
2194
  const state = Math.random().toString(36).substring(2);
2179
2195
  this.sessionStorage.setItem(`auth.state.${state}.location`, this.getRedirect(this.location.toString()));