Merge pull request #436 from matrix-org/rav/handle_broken_olm
Handle broken OlmAccounts
This commit is contained in:
commit
d3bc2b7df7
1 changed files with 42 additions and 21 deletions
|
@ -197,15 +197,31 @@ function _restoreFromLocalStorage() {
|
||||||
|
|
||||||
if (access_token && user_id && hs_url) {
|
if (access_token && user_id && hs_url) {
|
||||||
console.log("Restoring session for %s", user_id);
|
console.log("Restoring session for %s", user_id);
|
||||||
setLoggedIn({
|
try {
|
||||||
userId: user_id,
|
setLoggedIn({
|
||||||
deviceId: device_id,
|
userId: user_id,
|
||||||
accessToken: access_token,
|
deviceId: device_id,
|
||||||
homeserverUrl: hs_url,
|
accessToken: access_token,
|
||||||
identityServerUrl: is_url,
|
homeserverUrl: hs_url,
|
||||||
guest: is_guest,
|
identityServerUrl: is_url,
|
||||||
});
|
guest: is_guest,
|
||||||
return true;
|
});
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Unable to restore session", e);
|
||||||
|
|
||||||
|
var msg = e.message;
|
||||||
|
if (msg == "OLM.BAD_LEGACY_ACCOUNT_PICKLE") {
|
||||||
|
msg = "You need to log back in to generate and submit "
|
||||||
|
+ "end-to-end encryption keys. This is a once off; sorry "
|
||||||
|
+ "for the inconvenience.";
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't leak things into the new session
|
||||||
|
_clearLocalStorage();
|
||||||
|
|
||||||
|
throw new Error("Unable to restore previous session: " + msg);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("No previous session found.");
|
console.log("No previous session found.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -305,22 +321,27 @@ export function startMatrixClient() {
|
||||||
* a session has been logged out / ended.
|
* a session has been logged out / ended.
|
||||||
*/
|
*/
|
||||||
export function onLoggedOut() {
|
export function onLoggedOut() {
|
||||||
if (window.localStorage) {
|
_clearLocalStorage();
|
||||||
const hsUrl = window.localStorage.getItem("mx_hs_url");
|
|
||||||
const isUrl = window.localStorage.getItem("mx_is_url");
|
|
||||||
window.localStorage.clear();
|
|
||||||
// preserve our HS & IS URLs for convenience
|
|
||||||
// N.B. we cache them in hsUrl/isUrl and can't really inline them
|
|
||||||
// as getCurrentHsUrl() may call through to localStorage.
|
|
||||||
// NB. We do clear the device ID (as well as all the settings)
|
|
||||||
if (hsUrl) window.localStorage.setItem("mx_hs_url", hsUrl);
|
|
||||||
if (isUrl) window.localStorage.setItem("mx_is_url", isUrl);
|
|
||||||
}
|
|
||||||
stopMatrixClient();
|
stopMatrixClient();
|
||||||
|
|
||||||
dis.dispatch({action: 'on_logged_out'});
|
dis.dispatch({action: 'on_logged_out'});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _clearLocalStorage() {
|
||||||
|
if (!window.localStorage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const hsUrl = window.localStorage.getItem("mx_hs_url");
|
||||||
|
const isUrl = window.localStorage.getItem("mx_is_url");
|
||||||
|
window.localStorage.clear();
|
||||||
|
|
||||||
|
// preserve our HS & IS URLs for convenience
|
||||||
|
// N.B. we cache them in hsUrl/isUrl and can't really inline them
|
||||||
|
// as getCurrentHsUrl() may call through to localStorage.
|
||||||
|
// NB. We do clear the device ID (as well as all the settings)
|
||||||
|
if (hsUrl) window.localStorage.setItem("mx_hs_url", hsUrl);
|
||||||
|
if (isUrl) window.localStorage.setItem("mx_is_url", isUrl);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop all the background processes related to the current client
|
* Stop all the background processes related to the current client
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue