From a5c03c1540edfb42d8cda67ed11aed64497f1f72 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 24 Jan 2017 12:38:06 +0100 Subject: [PATCH] Make sure data is migrated before leaving registration page --- www/user/main.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/www/user/main.js b/www/user/main.js index b658ef76a..e45d48655 100644 --- a/www/user/main.js +++ b/www/user/main.js @@ -227,13 +227,26 @@ define([ proxy[k] = map[k]; }); - delete localStorage.FS_hash; - - if (!proxy[USERNAME_KEY]) { - proxy[USERNAME_KEY] = opt.name; - } - - next(); + var whenSynced = function () { + delete localStorage.FS_hash; + + if (!proxy[USERNAME_KEY]) { + proxy[USERNAME_KEY] = opt.name; + } + next(); + }; + + // Make sure the migration is synced in chainpad before continuing otherwise + // we may leave that page too early or trigger a reload in another tab before + // the migration is complete + var check = function () { + if (APP.realtime.getUserDoc() === APP.realtime.getAuthDoc()) { + whenSynced(); + return; + } + window.setTimeout(check, 300); + }; + check(); }); }); });