fix: reuse cached store list across logout/login instead of forcing refres

This commit is contained in:
root
2025-11-09 16:46:07 +01:00
parent b9a4414370
commit 0d09fdbcdc

View File

@@ -302,6 +302,7 @@ app.post('/api/auth/login', async (req, res) => {
const existingCredentials = credentialStore.get(profile.id);
const existingToken = existingCredentials?.token;
const previousSession = existingToken ? sessionStore.get(existingToken) : null;
if (existingToken) {
sessionStore.delete(existingToken);
}
@@ -316,17 +317,22 @@ app.post('/api/auth/login', async (req, res) => {
credentialStore.save(profile.id, { email, password, token: session.id });
scheduleConfig(session.id, config, settings);
const refreshResult = triggerStoreRefresh(session, { force: true, reason: 'login' });
if (previousSession?.storesCache) {
sessionStore.update(session.id, { storesCache: previousSession.storesCache });
}
const currentSession = sessionStore.get(session.id);
const needsRefresh = !isStoreCacheFresh(currentSession);
const refreshResult = needsRefresh ? triggerStoreRefresh(currentSession, { force: true, reason: 'login' }) : {};
return res.json({
token: session.id,
profile,
stores: session.storesCache?.data || [],
stores: sessionStore.get(session.id)?.storesCache?.data || [],
config,
isAdmin: isAdminUser,
adminSettings: isAdminUser ? settings : undefined,
storeRefreshJob: summarizeJob(refreshResult.job),
storesFresh: isStoreCacheFresh(session)
storeRefreshJob: summarizeJob(refreshResult?.job),
storesFresh: isStoreCacheFresh(sessionStore.get(session.id))
});
} catch (error) {
console.error('Login fehlgeschlagen:', error.message);