Add offline caching and refine Live Activity
This commit is contained in:
@@ -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