diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/hub-client.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/hub-client.js | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/hub-client.js b/packages/meshbay-hub/src/meshbay_hub/static/hub-client.js index e72961c..7ba6f92 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/hub-client.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/hub-client.js @@ -245,6 +245,22 @@ async function refreshAccessToken() { return _refreshing; } +/** + * Revoke this session's refresh token on the hub. + * + * Fire and forget, and read synchronously: the caller clears the session on the + * next line, and signing out must not wait on the network or fail with it. + */ +function logoutOnHub() { + const refreshToken = _auth && _auth.refreshToken; + if (!refreshToken) return; + platform.apiFetch(HUB + '/v1/users/logout', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ refresh_token: refreshToken }), + }).catch(() => {}); +} + /** Renew before it bites, rather than after. */ async function ensureFreshToken() { if (!_auth || !_auth.token) return null; @@ -290,5 +306,5 @@ export { cacheGroupIndex, getCachedGroupIndex, getAllCachedIndexes, clearAllCachedIndexes, _storeBundleKey, _loadBundleKey, _storeRecoveryKey, _loadRecoveryKey, _clearKeyDB, loadAuth, saveAuth, setAuth, setAuthChangeListener, - tokenLifeLeft, refreshAccessToken, ensureFreshToken, hubFetch, + tokenLifeLeft, refreshAccessToken, ensureFreshToken, logoutOnHub, hubFetch, }; |