fix: reject stale company profile and filter updates
This commit is contained in:
@@ -8,7 +8,7 @@ import { havuzuPuanla, profilMetni, profilTerimleri } from '../services/uyum';
|
||||
import { getToken } from '../services/auth';
|
||||
import { fetchLiveTenders, fetchTenderDetail, mergeUserState } from '../services/tenderApi';
|
||||
import { restoreSession, clearSession, getStoredUser } from '../services/auth';
|
||||
import { getAllUserData, setUserData, getPlan, bildirimleriGetir, bildirimOkundu, listDocuments } from '../services/account';
|
||||
import { getUserDataSnapshot, setUserData, getPlan, bildirimleriGetir, bildirimOkundu, listDocuments } from '../services/account';
|
||||
import { applyTenderStates, tenderStateKey, tenderSnapshot, publicTender, tenderSourceChanges } from '../services/tenderState';
|
||||
import { getTenderStates, saveTenderState } from '../services/account';
|
||||
import { SECTORS_LIST, INSTITUTION_TYPES_LIST } from '../data/constants';
|
||||
@@ -160,10 +160,12 @@ export const AppProvider = ({ children }) => {
|
||||
} catch { /* depolama kapalıysa kart bugünü gösterir */ }
|
||||
}, [authUser?.email]);
|
||||
|
||||
const dataRevisions=useRef({});
|
||||
// Giriş yapınca kullanıcı verisini SUNUCUDAN yükle (localStorage'ı ezer)
|
||||
useEffect(() => {
|
||||
notificationVersion.current++;notificationMutation.current=null;seenServerNotifications.current.clear();setNotificationError(null);setNotificationBusy(false);
|
||||
aiRunRef.current=null;setAiAnalyzing(false);setAiJobStatus('');
|
||||
dataRevisions.current={};
|
||||
setVeriSenkron(false); setPlan(null); setSaveError(null);
|
||||
setFavoriteKurumlar([]); setTeamMembers([]); setSavedFilters([]); setCompetitorWatchlist([]);
|
||||
setReminderSettings(defaultReminder()); setUserProfile(defaultProfile(authUser));
|
||||
@@ -176,9 +178,10 @@ export const AppProvider = ({ children }) => {
|
||||
ilkYazmaAtlanan.current.clear();
|
||||
savedTenderStates.current = {};
|
||||
const loadSession = getToken();
|
||||
Promise.all([getAllUserData(), getTenderStates()])
|
||||
.then(([v, records]) => {
|
||||
Promise.all([getUserDataSnapshot(), getTenderStates()])
|
||||
.then(([snapshot, records]) => {
|
||||
if (cancelled || getToken() !== loadSession) return;
|
||||
const v=snapshot.veri;dataRevisions.current=snapshot.revisions;
|
||||
setFavoriteKurumlar(v.favori_kurumlar || []);
|
||||
setTeamMembers(v.ekip || []);
|
||||
setSavedFilters(v.saved_filters || []);
|
||||
@@ -525,8 +528,9 @@ export const AppProvider = ({ children }) => {
|
||||
profileSaveLock.current=true;
|
||||
try {
|
||||
const profile={company:userProfile.company,website,scrapedCapabilities:capabilities,uyumEsigi:Math.max(0,Math.min(100,Number(threshold)||0))};
|
||||
await setUserData('firma_profil',profile);
|
||||
const saved=await setUserData('firma_profil',profile,dataRevisions.current.firma_profil ?? null);
|
||||
if(getToken()!==session)throw new Error('Oturum değişti; profil bu hesaba aktarılmadı.');
|
||||
dataRevisions.current.firma_profil=saved.revision;
|
||||
setUserProfile(previous=>({...previous,...profile}));
|
||||
return profile;
|
||||
}finally{profileSaveLock.current=false;}
|
||||
@@ -682,8 +686,9 @@ export const AppProvider = ({ children }) => {
|
||||
if(filterSaveLock.current){setSaveError('Önceki filtre kaydı sürüyor.');return false;}
|
||||
const session=getToken();filterSaveLock.current=true;setSavingCount(n=>n+1);setSaveError(null);
|
||||
try{
|
||||
await setUserData('saved_filters',next);
|
||||
const saved=await setUserData('saved_filters',next,dataRevisions.current.saved_filters ?? null);
|
||||
if(getToken()!==session)return false;
|
||||
dataRevisions.current.saved_filters=saved.revision;
|
||||
setSavedFilters(next);return true;
|
||||
}catch(error){if(getToken()===session)setSaveError(error.message);return false;}
|
||||
finally{filterSaveLock.current=false;setSavingCount(n=>n-1);}
|
||||
|
||||
Reference in New Issue
Block a user