Compare commits
4 commits
6af58755c1
...
f39875b810
Author | SHA1 | Date | |
---|---|---|---|
f39875b810 | |||
6e290bdb69 | |||
0001a50a5f | |||
e47a33bcd8 |
3 changed files with 178 additions and 152 deletions
|
@ -186,7 +186,11 @@
|
|||
F7ADCC68A8E44BA69FCA849E /* Fix Xcode 15 Bug */,
|
||||
B1AB92A327A24FB294681EDD /* Fix Xcode 15 Bug */,
|
||||
0E26E4D25E2E49C3AB2723FA /* Fix Xcode 15 Bug */,
|
||||
8589214E888941E1817F4C9F /* Remove signature files (Xcode workaround) */,
|
||||
5D0A324371BA4A5385A92DF5 /* Fix Xcode 15 Bug */,
|
||||
40472AFA41A8495E9D557630 /* Fix Xcode 15 Bug */,
|
||||
771057F6078145908B36B18B /* Fix Xcode 15 Bug */,
|
||||
7C1CC306C4DF48D4B5E1BDFB /* Fix Xcode 15 Bug */,
|
||||
2401E852B4D64D59BD803280 /* Remove signature files (Xcode workaround) */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
|
@ -1099,6 +1103,142 @@ fi";
|
|||
shellScript = "
|
||||
echo \"Remove signature files (Xcode workaround)\";
|
||||
rm -rf \"$CONFIGURATION_BUILD_DIR/MapLibre.xcframework-ios.signature\";
|
||||
";
|
||||
};
|
||||
5D0A324371BA4A5385A92DF5 /* Fix Xcode 15 Bug */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
name = "Fix Xcode 15 Bug";
|
||||
inputPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
);
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "if [ \"$XCODE_VERSION_MAJOR\" = \"1500\" ]; then
|
||||
echo \"Remove signature files (Xcode 15 workaround)\"
|
||||
find \"$BUILD_DIR/${CONFIGURATION}-iphoneos\" -name \"*.signature\" -type f | xargs -r rm
|
||||
fi";
|
||||
};
|
||||
C637A42109E14A1AA86AF639 /* Remove signature files (Xcode workaround) */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
name = "Remove signature files (Xcode workaround)";
|
||||
inputPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
);
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "
|
||||
echo \"Remove signature files (Xcode workaround)\";
|
||||
rm -rf \"$CONFIGURATION_BUILD_DIR/MapLibre.xcframework-ios.signature\";
|
||||
";
|
||||
};
|
||||
40472AFA41A8495E9D557630 /* Fix Xcode 15 Bug */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
name = "Fix Xcode 15 Bug";
|
||||
inputPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
);
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "if [ \"$XCODE_VERSION_MAJOR\" = \"1500\" ]; then
|
||||
echo \"Remove signature files (Xcode 15 workaround)\"
|
||||
find \"$BUILD_DIR/${CONFIGURATION}-iphoneos\" -name \"*.signature\" -type f | xargs -r rm
|
||||
fi";
|
||||
};
|
||||
B79BB2C3F48A4CC4B6830286 /* Remove signature files (Xcode workaround) */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
name = "Remove signature files (Xcode workaround)";
|
||||
inputPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
);
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "
|
||||
echo \"Remove signature files (Xcode workaround)\";
|
||||
rm -rf \"$CONFIGURATION_BUILD_DIR/MapLibre.xcframework-ios.signature\";
|
||||
";
|
||||
};
|
||||
771057F6078145908B36B18B /* Fix Xcode 15 Bug */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
name = "Fix Xcode 15 Bug";
|
||||
inputPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
);
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "if [ \"$XCODE_VERSION_MAJOR\" = \"1500\" ]; then
|
||||
echo \"Remove signature files (Xcode 15 workaround)\"
|
||||
find \"$BUILD_DIR/${CONFIGURATION}-iphoneos\" -name \"*.signature\" -type f | xargs -r rm
|
||||
fi";
|
||||
};
|
||||
83ACE65C55FE44EC820FD39A /* Remove signature files (Xcode workaround) */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
name = "Remove signature files (Xcode workaround)";
|
||||
inputPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
);
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "
|
||||
echo \"Remove signature files (Xcode workaround)\";
|
||||
rm -rf \"$CONFIGURATION_BUILD_DIR/MapLibre.xcframework-ios.signature\";
|
||||
";
|
||||
};
|
||||
7C1CC306C4DF48D4B5E1BDFB /* Fix Xcode 15 Bug */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
name = "Fix Xcode 15 Bug";
|
||||
inputPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
);
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "if [ \"$XCODE_VERSION_MAJOR\" = \"1500\" ]; then
|
||||
echo \"Remove signature files (Xcode 15 workaround)\"
|
||||
find \"$BUILD_DIR/${CONFIGURATION}-iphoneos\" -name \"*.signature\" -type f | xargs -r rm
|
||||
fi";
|
||||
};
|
||||
2401E852B4D64D59BD803280 /* Remove signature files (Xcode workaround) */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
name = "Remove signature files (Xcode workaround)";
|
||||
inputPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
);
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "
|
||||
echo \"Remove signature files (Xcode workaround)\";
|
||||
rm -rf \"$CONFIGURATION_BUILD_DIR/MapLibre.xcframework-ios.signature\";
|
||||
";
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
|
|
@ -152,19 +152,20 @@ export const memoryAsyncStorage = {
|
|||
storageLogger.debug("Set in memory cache", { key });
|
||||
|
||||
// Try to persist to AsyncStorage
|
||||
try {
|
||||
await AsyncStorage.setItem(key, value);
|
||||
storageLogger.debug("Persisted to AsyncStorage", { key });
|
||||
} catch (error) {
|
||||
storageLogger.warn(
|
||||
"Failed to persist to AsyncStorage, kept in memory only",
|
||||
{
|
||||
key,
|
||||
error: error.message,
|
||||
},
|
||||
);
|
||||
// Continue - value is at least in memory
|
||||
}
|
||||
(async () => {
|
||||
try {
|
||||
await AsyncStorage.setItem(key, value);
|
||||
storageLogger.debug("Persisted to AsyncStorage", { key });
|
||||
} catch (error) {
|
||||
storageLogger.warn(
|
||||
"Failed to persist to AsyncStorage, kept in memory only",
|
||||
{
|
||||
key,
|
||||
error: error.message,
|
||||
},
|
||||
);
|
||||
}
|
||||
})();
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -178,16 +179,18 @@ export const memoryAsyncStorage = {
|
|||
storageLogger.debug("Deleted from memory cache", { key });
|
||||
|
||||
// Try to delete from AsyncStorage
|
||||
try {
|
||||
await AsyncStorage.removeItem(key);
|
||||
storageLogger.debug("Deleted from AsyncStorage", { key });
|
||||
} catch (error) {
|
||||
storageLogger.warn("Failed to delete from AsyncStorage", {
|
||||
key,
|
||||
error: error.message,
|
||||
});
|
||||
// Continue - at least removed from memory
|
||||
}
|
||||
(async () => {
|
||||
try {
|
||||
await AsyncStorage.removeItem(key);
|
||||
storageLogger.debug("Deleted from AsyncStorage", { key });
|
||||
} catch (error) {
|
||||
storageLogger.warn("Failed to delete from AsyncStorage", {
|
||||
key,
|
||||
error: error.message,
|
||||
});
|
||||
// Continue - at least removed from memory
|
||||
}
|
||||
})();
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -242,14 +245,16 @@ export const memoryAsyncStorage = {
|
|||
storageLogger.info("Cleared memory cache");
|
||||
|
||||
// Try to clear AsyncStorage
|
||||
try {
|
||||
await AsyncStorage.clear();
|
||||
storageLogger.info("Cleared AsyncStorage");
|
||||
} catch (error) {
|
||||
storageLogger.warn("Failed to clear AsyncStorage", {
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
(async () => {
|
||||
try {
|
||||
await AsyncStorage.clear();
|
||||
storageLogger.info("Cleared AsyncStorage");
|
||||
} catch (error) {
|
||||
storageLogger.warn("Failed to clear AsyncStorage", {
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
})();
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -76,53 +76,6 @@ export default async function trackLocation() {
|
|||
isStaging: env.IS_STAGING,
|
||||
});
|
||||
|
||||
// Throttling configuration for auth reload only
|
||||
const AUTH_RELOAD_THROTTLE = 5000; // 5 seconds throttle
|
||||
|
||||
// The core auth reload function that will be throttled
|
||||
async function _reloadAuth() {
|
||||
locationLogger.info("Refreshing authentication token via sync endpoint");
|
||||
|
||||
try {
|
||||
// Get current auth state to check if we have an auth token
|
||||
const { authToken, userToken } = getAuthState();
|
||||
|
||||
if (!authToken) {
|
||||
locationLogger.warn("No auth token available for refresh");
|
||||
return;
|
||||
}
|
||||
|
||||
locationLogger.debug(
|
||||
"Auth token available, updating BackgroundGeolocation config",
|
||||
);
|
||||
|
||||
// Update BackgroundGeolocation config to include X-Auth-Token header
|
||||
await BackgroundGeolocation.setConfig({
|
||||
headers: {
|
||||
Authorization: `Bearer ${userToken}`, // Keep existing user token (may be expired)
|
||||
"X-Auth-Token": authToken, // Add auth token for refresh
|
||||
},
|
||||
});
|
||||
|
||||
// Trigger sync to refresh token
|
||||
await BackgroundGeolocation.changePace(true);
|
||||
await BackgroundGeolocation.sync();
|
||||
|
||||
locationLogger.info("Token refresh sync triggered successfully");
|
||||
} catch (error) {
|
||||
locationLogger.error("Failed to refresh authentication token", {
|
||||
error: error.message,
|
||||
stack: error.stack,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Create throttled version of auth reload with lodash
|
||||
const reloadAuth = throttle(_reloadAuth, AUTH_RELOAD_THROTTLE, {
|
||||
leading: true,
|
||||
trailing: false, // Prevent trailing calls to avoid duplicate refreshes
|
||||
});
|
||||
|
||||
// Handle auth function - no throttling or cooldown
|
||||
async function handleAuth(userToken) {
|
||||
locationLogger.info("Handling auth token update", {
|
||||
|
@ -282,46 +235,8 @@ export default async function trackLocation() {
|
|||
});
|
||||
|
||||
switch (statusCode) {
|
||||
case 200:
|
||||
// Successful response, check for token refresh
|
||||
try {
|
||||
const responseBody = response?.responseText
|
||||
? JSON.parse(response.responseText)
|
||||
: null;
|
||||
|
||||
if (responseBody?.userBearerJwt) {
|
||||
locationLogger.info(
|
||||
"Token refresh successful, updating stored token",
|
||||
);
|
||||
|
||||
// Use auth action to update both in-memory and persistent storage
|
||||
await authActions.setUserToken(responseBody.userBearerJwt);
|
||||
|
||||
// Update BackgroundGeolocation config with new token
|
||||
await BackgroundGeolocation.setConfig({
|
||||
headers: {
|
||||
Authorization: `Bearer ${responseBody.userBearerJwt}`,
|
||||
},
|
||||
});
|
||||
|
||||
locationLogger.debug(
|
||||
"Updated BackgroundGeolocation with refreshed token and removed X-Auth-Token header",
|
||||
);
|
||||
|
||||
Sentry.addBreadcrumb({
|
||||
message: "Token refreshed successfully",
|
||||
category: "geolocation-auth",
|
||||
level: "info",
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
locationLogger.debug("Failed to parse successful response", {
|
||||
error: e.message,
|
||||
responseText: response?.responseText,
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 410:
|
||||
case 401:
|
||||
// Auth token expired, logout
|
||||
locationLogger.info("Auth token expired (410), logging out");
|
||||
Sentry.addBreadcrumb({
|
||||
|
@ -331,40 +246,6 @@ export default async function trackLocation() {
|
|||
});
|
||||
authActions.logout();
|
||||
break;
|
||||
case 401:
|
||||
// Unauthorized: User token expired, refresh using throttled reload
|
||||
locationLogger.info("Unauthorized (401), attempting to refresh token");
|
||||
|
||||
// Add more detailed logging of the error response
|
||||
try {
|
||||
const errorBody = response?.responseText
|
||||
? JSON.parse(response.responseText)
|
||||
: null;
|
||||
locationLogger.debug("Unauthorized error details", {
|
||||
errorBody,
|
||||
errorType: errorBody?.error?.type,
|
||||
errorMessage: errorBody?.error?.message,
|
||||
errorPath: errorBody?.error?.errors?.[0]?.path,
|
||||
});
|
||||
|
||||
Sentry.addBreadcrumb({
|
||||
message: "Unauthorized - refreshing token",
|
||||
category: "geolocation-auth",
|
||||
level: "warning",
|
||||
data: {
|
||||
errorType: errorBody?.error?.type,
|
||||
errorMessage: errorBody?.error?.message,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
locationLogger.debug("Failed to parse error response", {
|
||||
error: e.message,
|
||||
responseText: response?.responseText,
|
||||
});
|
||||
}
|
||||
|
||||
reloadAuth();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue