Wait for user to login before fetching display preferences

This commit is contained in:
HighImKevin
2026-10-16 06:01:22 -04:00
parent cef8d3db28
commit 4fe99d368f
+15 -3
View File
@@ -117,12 +117,10 @@
* @returns {Promise<{ promise: Promise<object>, cached: object|null }>}
*/
getUserDisplayPreferences: async function(options = {}) {
ensureApiClient();
ensureLoggedIn();
const cacheOnly = options.cacheOnly === true;
let cachedDisplayPreferences = null;
// Cache hits must not wait on login (home paint can race signed-in)
if (__userDisplayPreferences) {
cachedDisplayPreferences = __userDisplayPreferences;
} else if (window.LocalStorageCache) {
@@ -142,6 +140,20 @@
};
}
// Network path: wait for login instead of hard-throwing ensureLoggedIn
ensureApiClient();
const loggedIn = await waitForLogin();
if (!loggedIn) {
if (cachedDisplayPreferences) {
WARN('getUserDisplayPreferences: login wait timed out; returning cache only');
return {
promise: Promise.resolve(cachedDisplayPreferences),
cached: cachedDisplayPreferences
};
}
throw new Error('User is not logged in');
}
// Wrap this in a promise to return with the cached data
const userDisplayPreferencesPromise = new Promise(async (resolve, reject) => {
try {