Add offline caching and refine Live Activity
This commit is contained in:
@@ -22,6 +22,7 @@ import { setRuntimeApiUrl, getApiUrl, DEFAULT_API_URL, invalidServerUrlMessage }
|
||||
import { clearAuthStorage, readStoredSessionUser } from "@/lib/auth-storage";
|
||||
import { normalizeInstanceUrl, saveStoredInstanceUrl } from "@/lib/instance-url";
|
||||
import { migrateStoredOfficialUrls } from "@/lib/official-url-migration";
|
||||
import { clearOfflineQueryCacheForAccount } from "@/lib/offline-cache";
|
||||
import { clearTimeClockPrefsForAccount } from "@/lib/time-clock-prefs";
|
||||
|
||||
export type RemoveAccountResult = {
|
||||
@@ -159,6 +160,7 @@ export function AccountsProvider({ children }: { children: ReactNode }) {
|
||||
const wasActive = activeAccountId === accountId;
|
||||
|
||||
await clearAuthStorage(authStoragePrefix(accountId));
|
||||
await clearOfflineQueryCacheForAccount(accountId);
|
||||
await clearTimeClockPrefsForAccount(accountId);
|
||||
|
||||
const nextAccounts = accounts.filter((account) => account.id !== accountId);
|
||||
|
||||
@@ -11,16 +11,39 @@ import {
|
||||
|
||||
type AuthClient = ReturnType<typeof createAuthClient>;
|
||||
|
||||
async function authFetch(input: RequestInfo | URL, init?: RequestInit) {
|
||||
try {
|
||||
return await fetch(input, init);
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.name === "AbortError") {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
message: "Could not connect to the server.",
|
||||
code: "NETWORK_ERROR",
|
||||
}),
|
||||
{
|
||||
status: 503,
|
||||
statusText: "Service Unavailable",
|
||||
headers: { "content-type": "application/json" },
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function createAppAuthClient(apiUrl: string, storagePrefix: string): AuthClient {
|
||||
return createAuthClient({
|
||||
baseURL: apiUrl,
|
||||
fetchOptions: {
|
||||
customFetchImpl: authFetch,
|
||||
},
|
||||
plugins: [
|
||||
expoClient({
|
||||
scheme: "beenvoice",
|
||||
storagePrefix,
|
||||
storage: SecureStore,
|
||||
// Avoid showing a cached session when cookies have already expired.
|
||||
disableCache: true,
|
||||
}),
|
||||
genericOAuthClient(),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user