[BUG] Runtime Error in AppContent Component: useUser Hook Fails with AWS Amplify Authenticator
Describe the bug
When running the application, an error occurs within the <AppContent> component related to AWS Amplify's authentication. Specifically, the error seems to originate from the usage of the useUser hook, causing the component tree to fail and triggering the ErrorBoundary. This prevents the application from rendering correctly and interrupts the user experience.
Error message:
The above error occurred in the <AppContent> component:
AppContent@http://localhost:5173/src/components/AppContent.tsx:38:20
AuthenticatorInternal@http://localhost:5173/node_modules/.vite/deps/@aws-amplify_ui-react.js?v=53795d0e:38959:31
AuthenticatorProvider@http://localhost:5173/node_modules/.vite/deps/@aws-amplify_ui-react.js?v=53795d0e:16899:31
Authenticator@http://localhost:5173/node_modules/.vite/deps/@aws-amplify_ui-react.js?v=53795d0e:38993:18
AuthAmplify@http://localhost:5173/src/components/AuthAmplify.tsx:23:21
AuthenticatorProvider@http://localhost:5173/node_modules/.vite/deps/@aws-amplify_ui-react.js?v=53795d0e:16899:31
ErrorBoundary@http://localhost:5173/node_modules/.vite/deps/react-error-boundary.js?v=53795d0e:18:5
App@http://localhost:5173/src/App.tsx:39:23
RenderedRoute@http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=51795d0e:4037:7
RenderErrorBoundary@http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=51795d0e:3994:5
DataRoutes@http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=51795d0e:5156:7
Router@http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=51795d0e:4423:7
RouterProvider@http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=51795d0e:4971:7
React will try to recreate this component tree from scratch using the error boundary you provided, ErrorBoundary.
To Reproduce
- Ensure project is up to date with the bec3aee4e63e5137a17ea5ed97b7ac5d38e4d3b1 PR.
- Clear
node_modules - Run
npm iin /frontend - Run
npm run dev - When started the application should show the error page
Screenshots
Additional context
-
Potential Causes Investigated:
- Context Misconfiguration: Ensured that all necessary context providers, such as
AuthProvider, are correctly wrapping the component tree. - Hook Implementation: Reviewed the
useUserhook to confirm it properly consumes context without missing providers. - AWS Amplify Configuration: Verified that Amplify is correctly initialized with the appropriate configuration files.
- Context Misconfiguration: Ensured that all necessary context providers, such as
-
Steps already taken:
- Verified that AWS Amplify is correctly configured and initialized in the project.
- Ensured that all context providers required by
useUserare properly set up in the component hierarchy. - Updated all dependencies to their latest versions to rule out compatibility issues.
- Attempted to isolate the issue by simplifying the
AppContentcomponent, but the error persists.
Tried npm ci && npm run dev with HEAD commit, but not reproduced.
Here's another section of the error:
It's worth noting that this happens after I have authenticated myself.
Things I've tried:
- Generated another
package-lock.json - Cleared browser cookies
- Tried multiple browsers just to make sure
I am confused since my fork is a 1:1 with this project with the exception of the additions of https://github.com/aws-samples/bedrock-claude-chat/commit/bec3aee4e63e5137a17ea5ed97b7ac5d38e4d3b1. I think it's also worth noting that this is happening in local development, I have not pushed it to the cloudformation stack as well. However, before I updated to https://github.com/aws-samples/bedrock-claude-chat/commit/bec3aee4e63e5137a17ea5ed97b7ac5d38e4d3b1 I could start the frontend with no problems at all.
Any suggestions are welcome.
Thank you in advance.
It still hasn't been reproduced. The cause could be the Vite plugins. I'll keep this issue open in case anyone else is facing the same problem.
@axelpina Could you please show the API response obtained by useConversationApi().getConversations() ?
https://github.com/aws-samples/bedrock-claude-chat/blob/bec3aee4e63e5137a17ea5ed97b7ac5d38e4d3b1/frontend/src/hooks/useConversationApi.ts#L23-L27
Response:
import { useSWRConfig } from "/node_modules/.vite/deps/swr.js?v=06194052";
import useHttp from "/src/hooks/useHttp.ts";
const useConversationApi = () => {
const http = useHttp();
const { mutate } = useSWRConfig();
const updateTitle = (conversationId, title) => {
return http.patch(`conversation/${conversationId}/title`, {
newTitle: title
});
};
return {
getConversations: () => {
return http.get("conversations", {
keepPreviousData: true
});
},
getConversation: (conversationId) => {
return http.get(
!conversationId ? null : `conversation/${conversationId}`,
{
keepPreviousData: true
}
);
},
postMessage: (input) => {
return http.post("conversation", {
...input
});
},
getRelatedDocuments: (input) => {
return http.post(
"conversation/related-documents",
{
...input
}
);
},
deleteConversation: (conversationId) => {
return http.delete(`conversation/${conversationId}`);
},
clearConversations: () => {
return http.delete("conversations");
},
updateTitle,
updateTitleWithGeneratedTitle: async (conversationId) => {
const res = await http.getOnce(`conversation/${conversationId}/proposed-title`);
return updateTitle(conversationId, res.data.title);
},
mutateConversations: (conversations, options) => {
return mutate("conversations", conversations, options);
}
};
};
export default useConversationApi;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInVzZUNvbnZlcnNhdGlvbkFwaS50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBNdXRhdG9yQ2FsbGJhY2ssIHVzZVNXUkNvbmZpZyB9IGZyb20gJ3N3cic7XHJcbmltcG9ydCB7XHJcbiAgQ29udmVyc2F0aW9uLFxyXG4gIENvbnZlcnNhdGlvbk1ldGEsXHJcbiAgR2V0UmVsYXRlZERvY3VtZW50c1JlcXVlc3QsXHJcbiAgR2V0UmVsYXRlZERvY3VtZW50c1Jlc3BvbnNlLFxyXG4gIFBvc3RNZXNzYWdlUmVxdWVzdCxcclxuICBQb3N0TWVzc2FnZVJlc3BvbnNlLFxyXG59IGZyb20gJy4uL0B0eXBlcy9jb252ZXJzYXRpb24nO1xyXG5pbXBvcnQgdXNlSHR0cCBmcm9tICcuL3VzZUh0dHAnO1xyXG5cclxuY29uc3QgdXNlQ29udmVyc2F0aW9uQXBpID0gKCkgPT4ge1xyXG4gIGNvbnN0IGh0dHAgPSB1c2VIdHRwKCk7XHJcbiAgY29uc3QgeyBtdXRhdGUgfSA9IHVzZVNXUkNvbmZpZygpO1xyXG5cclxuICBjb25zdCB1cGRhdGVUaXRsZSA9IChjb252ZXJzYXRpb25JZDogc3RyaW5nLCB0aXRsZTogc3RyaW5nKSA9PiB7XHJcbiAgICByZXR1cm4gaHR0cC5wYXRjaChgY29udmVyc2F0aW9uLyR7Y29udmVyc2F0aW9uSWR9L3RpdGxlYCwge1xyXG4gICA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0Esb0JBQW9CLENBQUMsbUJBQTJCO0FBQzlDLGFBQU8sS0FBSyxPQUFPLGdCQUFnQixjQUFjLEVBQUU7QUFBQSxJQUNyRDtBQUFBLElBQ0Esb0JBQW9CLE1BQU07QUFDeEIsYUFBTyxLQUFLLE9BQU8sZUFBZTtBQUFBLElBQ3BDO0FBQUEsSUFDQTtBQUFBLElBQ0EsK0JBQStCLE9BQU8sbUJBQTJCO0FBQy9ELFlBQU0sTUFBTSxNQUFNLEtBQUssUUFFcEIsZ0JBQWdCLGNBQWMsaUJBQWlCO0FBQ2xELGFBQU8sWUFBWSxnQkFBZ0IsSUFBSSxLQUFLLEtBQUs7QUFBQSxJQUNuRDtBQUFBLElBQ0EscUJBQXFCLENBQ25CLGVBSUEsWUFDRztBQUNILGFBQU8sT0FBTyxpQkFBaUIsZUFBZSxPQUFPO0FBQUEsSUFDdkQ7QUFBQSxFQUNGO0FBQ0Y7QUFFQSxlQUFlOyIsIm5hbWVzIjpbXX0=
It's worth pointing out that I haven't loaded up the backend for local development, only the frontend to make some changes. Before this update the frontend would start and load the UI, even without conversations.
@axelpina Sorry, what I wanted to see was the response to a GET request to the following backend API:
GET https://xxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/conversations
Here's a response from the GET in https://xxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/conversations:
NOTE: This is from the production environment. I have not configured the backend for local development. The only thing that I've done locally is make changes to the frontend. And again, the frontend spun up normally without issues before https://github.com/aws-samples/bedrock-claude-chat/commit/bec3aee4e63e5137a17ea5ed97b7ac5d38e4d3b1
@statefb I apologize for diverting this ticket, but I wanted to avoid opening a new one as my question is specific to starting the backend for development and testing. After exporting the required environment variables, the backend starts without issue. However, when I start the frontend, I am unable to access Claude. Additionally I am unable to visualize my bots as well.
# export TABLE_NAME=BedrockChatStack-DatabaseConversationTablexxxxxx
# export ACCOUNT=xxxxx
# export REGION=us-east-1
# export BEDROCK_REGION=us-east-1
# export DOCUMENT_BUCKET=bedrockchatstack-documentbucketxxxxx
# export LARGE_MESSAGE_BUCKET=bedrockchatstack-largemessagebucketxxxxx
# export USER_POOL_ID=us-east-1_xxxxx
# export CLIENT_ID=xxxxxxxxxxxxxxxxxxxxxxx
Need clarification on using the backend for local development.
Thank you in advance.
This issue has been labeled as "stale" due to no response by the reporter within 1 month (and 14 days after last commented by someone). And it will be closed automatically 14 days later if not responded.