diff --git a/server.js b/server.js index 5b2f9b5..a40ddfa 100644 --- a/server.js +++ b/server.js @@ -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);