reset mobile context caches on user identity changes

This commit is contained in:
dimitar committed 2026-03-29 15:38:51 +02:00
1 parent aa662a9b74
commit 34e88bdde5
6 files changed
+79 -2

No files matched your search

+17 -1
View File
@@ -1,4 +1,10 @@
import React, { createContext, useContext, useState, useCallback } from "react";
import React, {
createContext,
useContext,
useState,
useCallback,
useEffect,
} from "react";
import { useUser, useAuth } from "@clerk/clerk-expo";
import { getUserStatistics } from "../api/statistics";
import type { UserStatisticsResponse } from "../api/types";
@@ -75,11 +81,21 @@ export function StatisticsProvider({
const clearCache = useCallback(() => {
setStatistics(null);
setLoading(false);
setLastFetchTime(0);
setError(null);
log.debug("Statistics cache cleared");
}, []);
useEffect(() => {
clearCache();
if (user?.id) {
log.debug("Statistics cache reset for user", { userId: user.id });
} else {
log.debug("Statistics cache reset on sign-out");
}
}, [user?.id, clearCache]);
const forceRefresh = useCallback(async () => {
if (!user?.id) return;