#HTTP Intercepter Unauthorized Expo
1 messages · Page 1 of 1 (latest)
Hi @pastel bobcat. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
I'm sorry, but the knowledge sources do not contain a complete example of implementing an HTTP interceptor in Expo that catches all unauthorized (401) responses and pushes a modal. However, I can share some relevant patterns and partial solutions from the sources:
-
Convex does not provide a built-in HTTP interceptor for Expo/React Native. Error handling for unauthorized access is typically done at the query/mutation level, where you can throw and catch errors, and then display UI accordingly. For example, you can throw an error in your Convex function if the user is not authenticated, and then catch it in your frontend to show a modal or other UI element. See this discussion on error handling and the Convex error handling docs.
-
For HTTP actions, you can return a 401 response if the user is not authenticated, and then handle that in your frontend fetch logic. For example:
// convex/httpAction.js
export const generateUrlForToken = httpAction(async (ctx, request) => {
const identity = await ctx.auth.getUserIdentity();
if (identity == null) {
return new Response("No identity found", { status: 401 });
}
// ...rest of your logic
});
(Source)
- On the client side, you would need to check the response status after each fetch and, if it's 401, trigger your modal. There is no code in the sources showing a global HTTP interceptor for Expo, but you can wrap your fetch calls:
async function fetchWithAuth(url, options) {
const response = await fetch(url, options);
if (response.status === 401) {
// Show your modal here
// e.g., setModalVisible(true)
}
return response;
}
- For Convex queries/mutations, you can use error boundaries or custom hooks to catch errors and show UI, as discussed in this thread.
Summary:
There is no out-of-the-box HTTP interceptor pattern for Expo in the knowledge sources, but you can handle unauthorized responses by checking response status in your fetch logic and showing a modal as needed. For Convex queries/mutations, use error boundaries or custom error handling to trigger UI changes.