-
-
Notifications
You must be signed in to change notification settings - Fork 146
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: Prevent article page from calling bookmarks for unauthenticated users (#1138) #1165
Fix: Prevent article page from calling bookmarks for unauthenticated users (#1138) #1165
Conversation
@shanksxz is attempting to deploy a commit to the Codú Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe changes in the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Hello @shanksxz, thanks for opening your first Pull Request. The maintainers will review this Pull Request and provide feedback as soon as possible. Keep up the great work! |
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: 0
🧹 Outside diff range and nitpick comments (1)
components/ArticlePreview/ArticlePreview.tsx (1)
Line range hint
91-103
: Approve changes, but suggest flow improvement.The addition of the session check before bookmarking aligns well with the PR objectives. However, there's a potential issue with the function's flow:
- If there's no session, it calls
signIn()
.- It then continues to execute
bookmark({ postId, setBookmarked })
, which might still fail as the user hasn't completed the sign-in process yet.Consider refactoring the function to handle the sign-in flow more robustly:
const bookmarkPost = async (postId: string, setBookmarked = true) => { if (bookmarkStatus === "loading") return; if (!session) { signIn(); return; // Exit the function after initiating sign-in } try { return await bookmark({ postId, setBookmarked }); } catch (err) { Sentry.captureException(err); } };This change ensures that the bookmark action is only attempted when a session exists, preventing potential errors from unauthenticated API calls.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- components/ArticlePreview/ArticlePreview.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (3)
components/ArticlePreview/ArticlePreview.tsx (3)
58-64
: LGTM! Changes align with PR objectives.The modifications to the
useSession
hook placement and theapi.post.myBookmarks.useQuery
call effectively prevent bookmark fetching for unauthenticated users. Theenabled: !!session
option ensures that the query is only executed when a session exists, which aligns perfectly with the PR objectives and resolves the issue mentioned in #1138.
Line range hint
170-179
: LGTM! Consistent handling of unauthenticated users.The changes to the bookmark button's onClick handler are well-implemented and consistent with the PR objectives. The session check prevents unauthenticated users from attempting to bookmark and instead prompts them to sign in. This change, combined with the earlier modifications, ensures a cohesive approach to handling unauthenticated users throughout the component.
Line range hint
1-258
: Summary: Changes effectively address PR objectivesThe modifications in this file successfully prevent bookmark fetching and actions for unauthenticated users, aligning well with the PR objectives and resolving the issue mentioned in #1138. The changes consistently handle user authentication across different parts of the component, improving the overall user experience and eliminating console errors for unauthenticated users.
A minor suggestion was made to improve the flow in the
bookmarkPost
function, but overall, the implementation effectively achieves the goals of the pull request.
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.
This works great, thanks.
PS. @NiallJoeMaher
Separately this has me wondering why this query is done in the ArticlePreview component?
The resulting data is not used here at all.
The refetch is used when the user bookmarks an article, but this is definitely not the way to handle this.
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.
Hey @shanksxz
Can you please run the prettier script, and commit the changes. Thanks.
npm run prettier:fix
yeah true |
sure. |
Uh oh! @JohnAllenTech, the image you shared is missing helpful alt text. Check #1165 (comment). Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image. Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
✨ Codu Pull Request 💻
Fixes #1138
Pull Request details
Any Breaking changes
Associated Screenshots