Compare commits

..

2 commits

Author SHA1 Message Date
6a773367d4 fix: prevent race condition 2025-06-29 12:39:07 +02:00
70cca596e4 chore: improve logging 2025-06-29 12:35:53 +02:00
2 changed files with 9 additions and 2 deletions

View file

@ -204,10 +204,10 @@ export default async function trackLocation() {
// Create throttled version of auth reload with lodash
const reloadAuth = throttle(_reloadAuth, AUTH_RELOAD_THROTTLE, {
leading: true,
trailing: true,
trailing: false, // Prevent trailing calls to avoid duplicate refreshes
});
BackgroundGeolocation.onHttp((response) => {
BackgroundGeolocation.onHttp(async (response) => {
// Log the full response including headers if available
locationLogger.debug("HTTP response received", {
status: response?.status,

View file

@ -153,6 +153,7 @@ export default createAtom(({ get, merge, getActions }) => {
}
if (isLoading()) {
authLogger.info("Auth is already loading, waiting for completion");
await loadingPromise;
return true;
}
@ -162,9 +163,15 @@ export default createAtom(({ get, merge, getActions }) => {
try {
startLoading();
authLogger.debug("Deleting userToken for refresh");
await secureStore.deleteItemAsync("userToken");
await init();
return true;
} catch (error) {
authLogger.error("Auth reload failed", { error: error.message });
throw error;
} finally {
// Clear reloading state even if there was an error
merge({ isReloading: false });