mirror of
https://github.com/element-hq/element-web
synced 2024-11-25 02:35:48 +03:00
Merge pull request #2975 from matrix-org/dbkr/fix_sso_2
Fix Single Sign-on
This commit is contained in:
commit
cfe917e489
3 changed files with 24 additions and 3 deletions
|
@ -369,7 +369,7 @@ async function _doSetLoggedIn(credentials, clearStorage) {
|
|||
// If there's an inconsistency between account data in local storage and the
|
||||
// crypto store, we'll be generally confused when handling encrypted data.
|
||||
// Show a modal recommending a full reset of storage.
|
||||
if (results.dataInLocalStorage && !results.dataInCryptoStore) {
|
||||
if (results.dataInLocalStorage && results.cryptoInited && !results.dataInCryptoStore) {
|
||||
const signOut = await _showStorageEvictedDialog();
|
||||
if (signOut) {
|
||||
await _clearStorage();
|
||||
|
|
|
@ -121,6 +121,7 @@ class MatrixClientPeg {
|
|||
// check that we have a version of the js-sdk which includes initCrypto
|
||||
if (this.matrixClient.initCrypto) {
|
||||
await this.matrixClient.initCrypto();
|
||||
StorageManager.setCryptoInitialised(true);
|
||||
}
|
||||
} catch (e) {
|
||||
if (e && e.name === 'InvalidCryptoStoreError') {
|
||||
|
|
|
@ -50,11 +50,15 @@ export async function checkConsistency() {
|
|||
|
||||
let dataInLocalStorage = false;
|
||||
let dataInCryptoStore = false;
|
||||
let cryptoInited = false;
|
||||
let healthy = true;
|
||||
|
||||
if (localStorage) {
|
||||
dataInLocalStorage = localStorage.length > 0;
|
||||
log(`Local storage contains data? ${dataInLocalStorage}`);
|
||||
|
||||
cryptoInited = localStorage.getItem("mx_crypto_initialised");
|
||||
log(`Crypto initialised? ${cryptoInited}`);
|
||||
} else {
|
||||
healthy = false;
|
||||
error("Local storage cannot be used on this browser");
|
||||
|
@ -84,10 +88,11 @@ export async function checkConsistency() {
|
|||
track("Crypto store disabled");
|
||||
}
|
||||
|
||||
if (dataInLocalStorage && !dataInCryptoStore) {
|
||||
if (dataInLocalStorage && cryptoInited && !dataInCryptoStore) {
|
||||
healthy = false;
|
||||
error(
|
||||
"Data exists in local storage but not in crypto store. " +
|
||||
"Data exists in local storage and crypto is marked as initialised " +
|
||||
" but no data found in crypto store. " +
|
||||
"IndexedDB storage has likely been evicted by the browser!",
|
||||
);
|
||||
track("Crypto store evicted");
|
||||
|
@ -104,6 +109,7 @@ export async function checkConsistency() {
|
|||
return {
|
||||
dataInLocalStorage,
|
||||
dataInCryptoStore,
|
||||
cryptoInited,
|
||||
healthy,
|
||||
};
|
||||
}
|
||||
|
@ -155,3 +161,17 @@ export function trackStores(client) {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether crypto has ever been successfully
|
||||
* initialised on this client.
|
||||
* StorageManager uses this to determine whether indexeddb
|
||||
* has been wiped by the browser: this flag is saved to localStorage
|
||||
* and if it is true and not crypto data is found, an error is
|
||||
* presented to the user.
|
||||
*
|
||||
* @param {bool} cryptoInited True if crypto has been set up
|
||||
*/
|
||||
export function setCryptoInitialised(cryptoInited) {
|
||||
localStorage.setItem("mx_crypto_initialised", cryptoInited);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue