diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-10-04 12:10:43 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-10-05 10:25:45 +0200 |
commit | 8c023eeabdb3874470e5db1a756ed1b62ea3ecf9 (patch) | |
tree | 19edbef8c3495c6d99b92d487a3f9561604959f2 /core/src/OC | |
parent | 87ad219dafd60b9b733a03a34404ab828b195cdb (diff) | |
download | nextcloud-server-8c023eeabdb3874470e5db1a756ed1b62ea3ecf9.tar.gz nextcloud-server-8c023eeabdb3874470e5db1a756ed1b62ea3ecf9.zip |
Emit an event when the CSRF token changes
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'core/src/OC')
-rw-r--r-- | core/src/OC/index.js | 12 | ||||
-rw-r--r-- | core/src/OC/requesttoken.js | 14 |
2 files changed, 15 insertions, 11 deletions
diff --git a/core/src/OC/index.js b/core/src/OC/index.js index 0c95fe3e95f..01964b3ca4a 100644 --- a/core/src/OC/index.js +++ b/core/src/OC/index.js @@ -19,6 +19,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import { subscribe } from '@nextcloud/event-bus' + import { addScript, addStyle } from './legacy-loader' import { ajaxConnectionLostHandler, @@ -67,8 +69,7 @@ import { getProtocol } from './host' import { - getToken as getRequestToken, - subscribe as subscribeToRequestTokenChange + getToken as getRequestToken } from './requesttoken' import { hideMenus, @@ -258,4 +259,9 @@ export default { } // Keep the request token prop in sync -subscribeToRequestTokenChange(token => { OC.requestToken = token }) +subscribe('csrf-token-update', e => { + OC.requestToken = e.token + + // Logging might help debug (Sentry) issues + console.info('OC.requestToken changed', e.token) +}) diff --git a/core/src/OC/requesttoken.js b/core/src/OC/requesttoken.js index a92eb169577..91b18069d75 100644 --- a/core/src/OC/requesttoken.js +++ b/core/src/OC/requesttoken.js @@ -19,8 +19,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import { emit } from '@nextcloud/event-bus' + let token = document.getElementsByTagName('head')[0].getAttribute('data-requesttoken') -const observers = [] /** * @returns {string} @@ -28,15 +29,12 @@ const observers = [] export const getToken = () => token /** - * @param {Function} observer observer - * @returns {number} - */ -export const subscribe = observer => observers.push(observer) - -/** * @param {String} newToken new token */ export const setToken = newToken => { token = newToken - observers.forEach(o => o(token)) + + emit('csrf-token-update', { + token + }) } |