-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: chat navigation #175
fix: chat navigation #175
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe recent updates enhance user experience by refining redirection and login checks across the application. Changes include improved handling of user authentication states, enhanced loading mechanisms for thread lists, and adjustments in navigation components to better manage null values and user interface consistency. Changes
Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (4)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
const supabase = await createSupabaseServerClient() | ||
const { | ||
data: { user } | ||
} = await supabase.auth.getUser() | ||
|
||
// only logged in users can chat | ||
// we most redirect here to prevent layout flickering | ||
if (!user?.email) redirect(`/auth/sign-in`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure proper error handling for asynchronous operations in ChatLayout
.
- const supabase = await createSupabaseServerClient()
- const {
- data: { user }
- } = await supabase.auth.getUser()
+ try {
+ const supabase = await createSupabaseServerClient()
+ const {
+ data: { user }
+ } = await supabase.auth.getUser()
+ if (!user?.email) redirect(`/auth/sign-in`)
+ } catch (error) {
+ console.error('Failed to authenticate user:', error);
+ redirect(`/error`);
+ }
The original code does not handle potential errors from asynchronous operations, which could lead to unhandled promise rejections. It's crucial to wrap these operations in a try-catch block to handle errors gracefully and redirect the user to an error page if necessary.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
const supabase = await createSupabaseServerClient() | |
const { | |
data: { user } | |
} = await supabase.auth.getUser() | |
// only logged in users can chat | |
// we most redirect here to prevent layout flickering | |
if (!user?.email) redirect(`/auth/sign-in`) | |
try { | |
const supabase = await createSupabaseServerClient() | |
const { | |
data: { user } | |
} = await supabase.auth.getUser() | |
// only logged in users can chat | |
// we most redirect here to prevent layout flickering | |
if (!user?.email) redirect(`/auth/sign-in`) | |
} catch (error) { | |
console.error('Failed to authenticate user:', error); | |
redirect(`/error`); | |
} |
@@ -10,7 +10,8 @@ export default async function IndexPage() { | |||
const { | |||
data: { user } | |||
} = await supabase.auth.getUser() | |||
if (!user.email) redirect(`/auth/sign-in`) | |||
|
|||
if (!user?.email) redirect(`/auth/sign-in`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refine redirection logic to handle potential null values more robustly.
- if (!user?.email) redirect(`/auth/sign-in`)
+ if (!user || !user.email) redirect(`/auth/sign-in`)
Using optional chaining (user?.email
) is concise but may not explicitly handle cases where user
is null or undefined. It's safer to check both user
and user.email
explicitly to avoid any potential issues with falsy values.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
if (!user?.email) redirect(`/auth/sign-in`) | |
if (!user || !user.email) redirect(`/auth/sign-in`) |
@@ -22,7 +23,7 @@ export default async function IndexPage() { | |||
const jwt = cookies().get('hasuraJwt').value || '' | |||
|
|||
// NOTE: maybe we should use same expiration time | |||
if (!jwt || isTokenExpired(jwt) || !user) redirect(`/auth/sign-in`) | |||
if (!jwt || isTokenExpired(jwt)) redirect(`/auth/sign-in`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding logging for debugging and monitoring token expiration handling.
Adding logging before redirecting due to token expiration can help in debugging and monitoring the application, especially in production environments. This could be as simple as:
console.log(`Redirecting because token expired or is missing: ${jwt}`);
// if no initial threads passed dont try to load more | ||
// TODO: get thread count from server db query | ||
if (!loadMoreRef.current || !initialThreads?.length) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure proper cleanup of IntersectionObserver to prevent memory leaks.
- observer.unobserve(entry.target)
+ observer.disconnect()
It's important to ensure that the IntersectionObserver
is properly cleaned up when the component unmounts to prevent memory leaks. The current implementation only unobserves the target, but it's safer to disconnect the observer entirely.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
// if no initial threads passed dont try to load more | |
// TODO: get thread count from server db query | |
if (!loadMoreRef.current || !initialThreads?.length) return | |
// if no initial threads passed dont try to load more | |
// TODO: get thread count from server db query | |
if (!loadMoreRef.current || !initialThreads?.length) return | |
observer.disconnect() |
@@ -91,6 +93,7 @@ export function ThreadList({ | |||
|
|||
return ( | |||
<div className="flex flex-col w-full gap-8 py-5" key={queryKey[0]}> | |||
{!threads.length ? <div>No threads founds</div> : null} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve user feedback by providing more detailed messages when no threads are found.
Consider enhancing the user experience by providing a more detailed message when no threads are found, such as:
<div>No threads found. Please try again later or contact support if the issue persists.</div>
This provides clearer communication and potential next steps for the user.
@@ -40,7 +41,7 @@ export default function SidebarLink({ category }: { category: Category }) { | |||
if ( | |||
category.chatbots.length && | |||
category.chatbots.filter( | |||
c => c.chatbot.name.toLowerCase().trim() === chatbot.trim() | |||
c => c.chatbot.name.toLowerCase().trim() === chatbot?.trim() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate the presence of chatbot
before accessing its properties to prevent runtime errors.
- c => c.chatbot.name.toLowerCase().trim() === chatbot?.trim()
+ c => c.chatbot && c.chatbot.name.toLowerCase().trim() === chatbot?.trim()
It's important to check that c.chatbot
is not null or undefined before accessing c.chatbot.name
to prevent potential runtime errors. This change ensures that the code is more robust and can handle cases where c.chatbot
might be null.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
c => c.chatbot.name.toLowerCase().trim() === chatbot?.trim() | |
c => c.chatbot && c.chatbot.name.toLowerCase().trim() === chatbot?.trim() |
Summary by CodeRabbit
New Features
Bug Fixes
null
values in sidebar links to prevent errors.Style
ThreadList
component, including better handling of scenarios where no threads are found.