-
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 auth bug #109
fix: chat auth bug #109
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe essence of the recent updates revolves around enhancing user authentication and redirection mechanisms across various components of an application. By integrating a more efficient Supabase client creation and refining user redirection based on authentication states, the updates aim to streamline user experience, ensuring users are smoothly guided towards necessary actions like signing in, whenever required. Changes
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: 7
Review Status
Configuration used: CodeRabbit UI
Files selected for processing (4)
- apps/masterbots.ai/app/auth/callback/route.ts (2 hunks)
- apps/masterbots.ai/app/c/[chatbot]/[threadId]/page.tsx (1 hunks)
- apps/masterbots.ai/app/c/[chatbot]/page.tsx (1 hunks)
- apps/masterbots.ai/app/c/page.tsx (1 hunks)
Additional comments not posted (2)
apps/masterbots.ai/app/c/page.tsx (1)
21-21
: Consider consolidating redirection conditions for efficiency.The redirection conditions based on JWT, token expiration, and user presence are scattered across the file. It might be more efficient to consolidate these conditions into a single block to avoid redundancy and improve readability.
apps/masterbots.ai/app/auth/callback/route.ts (1)
16-16
: Successfully replacedcreateServerClient
withcreateSupabaseServerClient
for asynchronous Supabase client creation.This change likely enhances security and efficiency in the authentication process by utilizing an asynchronous method to create the Supabase client.
@@ -11,13 +11,14 @@ export default async function IndexPage() { | |||
const { | |||
data: { user } | |||
} = await supabase.auth.getUser() | |||
if (!user || !user.email) throw new Error('user not found') | |||
if (!user || !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 handling of asynchronous redirect
calls.
- if (!user || !user.email) redirect(`/auth/sign-in`)
+ if (!user || !user.email) return redirect(`/auth/sign-in`)
The redirect
function is asynchronous and should be returned to ensure the redirection is properly handled and no further code is executed.
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 || !user.email) redirect(`/auth/sign-in`) | |
if (!user || !user.email) return redirect(`/auth/sign-in`) |
const dbUserProfile = await getUser({ | ||
email: user.email, | ||
adminSecret: process.env.HASURA_GRAPHQL_ADMIN_SECRET || '' | ||
}) | ||
|
||
if (!dbUserProfile) throw new Error('user not found') | ||
if (!dbUserProfile) 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 handling of asynchronous redirect
calls when the user profile is not found.
- if (!dbUserProfile) redirect(`/auth/sign-in`)
+ if (!dbUserProfile) return redirect(`/auth/sign-in`)
Similar to the previous comment, the redirect
function should be returned to ensure proper execution flow.
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 (!dbUserProfile) redirect(`/auth/sign-in`) | |
if (!dbUserProfile) return redirect(`/auth/sign-in`) |
if (!user || !user.email) | ||
redirect(`/auth/sign-in?next=/${params.chatbot}/${params.threadId}`) |
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 handling of asynchronous redirect
calls with specific parameters.
- if (!user || !user.email)
- redirect(`/auth/sign-in?next=/${params.chatbot}/${params.threadId}`)
+ if (!user || !user.email) return redirect(`/auth/sign-in?next=/${params.chatbot}/${params.threadId}`)
The redirect
function is asynchronous and should be returned to ensure the redirection is properly handled and no further code is executed. Additionally, including specific parameters in the redirect URL is a good practice for improving user experience.
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 || !user.email) | |
redirect(`/auth/sign-in?next=/${params.chatbot}/${params.threadId}`) | |
if (!user || !user.email) return redirect(`/auth/sign-in?next=/${params.chatbot}/${params.threadId}`) |
redirect(`/auth/sign-in?next=/${params.chatbot}/${params.threadId}`) | ||
|
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 handling of asynchronous redirect
calls with specific parameters based on JWT and user conditions.
- if (!jwt || isTokenExpired(jwt) || !user)
- redirect(`/auth/sign-in?next=/${params.chatbot}/${params.threadId}`)
+ if (!jwt || isTokenExpired(jwt) || !user) return redirect(`/auth/sign-in?next=/${params.chatbot}/${params.threadId}`)
Similar to the previous comment, the redirect
function should be returned to ensure proper execution flow. Including specific parameters in the redirect URL is commendable for guiding users appropriately.
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.
redirect(`/auth/sign-in?next=/${params.chatbot}/${params.threadId}`) | |
if (!jwt || isTokenExpired(jwt) || !user) return redirect(`/auth/sign-in?next=/${params.chatbot}/${params.threadId}`) |
@@ -20,17 +20,18 @@ export default async function BotThreadsPage({ | |||
const { | |||
data: { user } | |||
} = await supabase.auth.getUser() | |||
if (!user || !user.email) throw new Error('user not found') | |||
if (!user || !user.email) redirect(`/auth/sign-in?next=/${params.chatbot}`) |
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 handling of asynchronous redirect
calls with specific parameters.
- if (!user || !user.email) redirect(`/auth/sign-in?next=/${params.chatbot}`)
+ if (!user || !user.email) return redirect(`/auth/sign-in?next=/${params.chatbot}`)
The redirect
function is asynchronous and should be returned to ensure the redirection is properly handled and no further code is executed. Including specific parameters in the redirect URL is a good practice for improving user experience.
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 || !user.email) redirect(`/auth/sign-in?next=/${params.chatbot}`) | |
if (!user || !user.email) return redirect(`/auth/sign-in?next=/${params.chatbot}`) |
const userProfile = await getUser({ | ||
email: user.email, | ||
adminSecret: process.env.HASURA_GRAPHQL_ADMIN_SECRET || '' | ||
}) | ||
|
||
if (!userProfile) throw new Error('user not found') | ||
if (!userProfile) redirect(`/auth/sign-in?next=/${params.chatbot}`) |
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 handling of asynchronous redirect
calls when the user profile is not found.
- if (!userProfile) redirect(`/auth/sign-in?next=/${params.chatbot}`)
+ if (!userProfile) return redirect(`/auth/sign-in?next=/${params.chatbot}`)
Similar to the previous comments, the redirect
function should be returned to ensure proper execution flow. Including specific parameters in the redirect URL is commendable for guiding users appropriately.
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 (!userProfile) redirect(`/auth/sign-in?next=/${params.chatbot}`) | |
if (!userProfile) return redirect(`/auth/sign-in?next=/${params.chatbot}`) |
if (!jwt || isTokenExpired(jwt)) | ||
redirect(`/auth/sign-in?next=/${params.chatbot}`) |
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 handling of asynchronous redirect
calls with specific parameters based on JWT conditions.
- if (!jwt || isTokenExpired(jwt))
- redirect(`/auth/sign-in?next=/${params.chatbot}`)
+ if (!jwt || isTokenExpired(jwt)) return redirect(`/auth/sign-in?next=/${params.chatbot}`)
The redirect
function is asynchronous and should be returned to ensure the redirection is properly handled and no further code is executed. Including specific parameters in the redirect URL is commendable for guiding users appropriately.
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 (!jwt || isTokenExpired(jwt)) | |
redirect(`/auth/sign-in?next=/${params.chatbot}`) | |
if (!jwt || isTokenExpired(jwt)) return redirect(`/auth/sign-in?next=/${params.chatbot}`) |
* devops: force deployment * devops: force deployment * devops: force deployment * devops: update cloudbuild.yml * devops: cloud logging only * devops: remove cloudbuild.yml * chore: update bunlock * feat: browse as homepage, work early access (#62) * feat: browse as home * feat: browse as home * feat: remove tabs * feat: supabase auth (#63) * feat: supabase auth * feat: supabase auth * feat: supabase auth * feat: supabase auth * feat: supabase auth * feat: supabase auth * feat: supabase auth * feat: supabase auth * feat: supabase auth * feat: pro form * devops: lighthouse reports on prs (#64) * devops: lighthouse reports on prs * chore: cleanup * devops: lighthouse ci (#65) * devops: lighthouse reports on prs * chore: cleanup * chore: test lighthouse ci * devops: lighthouse reports on pr * devops: use zentered/vercel-preview-url * devops: lighthouse ci github action (#66) * chore: test lighthouse ci * devops: fix version on github actions * chore: cleanup * devops: debug lighthouse github action (#67) * chore: test lighthouse ci * devops: debug github actions * devops: correct project id on github actions (#69) * devops: debug github actions * devops: correct project id * devops: correct vercel team id (#70) * devops: debug github actions * devops: correct vercel team id * devops: debug github actions (#71) * devops: debug github actions * devops: use actions/checkout v4 * devops: add protocol to lhci url * devops: use foo-software/lighthouse-check-action (#72) * devops: debug github actions * devops: debug github actions * devops: use foo-software/lighthouse-check-action * devops: lhci budget path (#73) * devops: debug github actions * devops: lhci budget path * devops: disable lhci budget (#74) * devops: debug github actions * devops: disable lhci budget * devops: run lhci on bot and user landings (#75) * devops: debug github actions * devops: run lhci on bot and user landings * devops: run lhci on bot and user landings (#76) * devops: debug github actions * devops: run lhci on bot and user landings * devops: run lhci on bot and user landings * devops: run lhci on bot and user landings (#77) * devops: debug github actions * devops: run lhci on bot and user landings * devops: debug lhci results comment (#78) * devops: debug github actions * devops: debug lhci results comment * devops: debug lhci results comment (#79) * devops: debug github actions * devops: debug lhci results comment * feat: thread landing (#80) * devops: debug lhci results comment * feat: thread landing * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment (#83) * chore: cleanup * devops: debug lhci results comment * devops: debug lhci results comment (#84) * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment (#85) * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment (#86) * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment (#88) * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment (#89) * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment * devops: lhci results table comment * devops: debug lhci results comment * devops: lhci results table comment (#90) * devops: lhci results table comment * devops: lhci results table comment (#91) * devops: lhci results table comment * devops: lhci results table comment * devops: lhci results table comment * devops: debug lhci results comment (#92) * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment (#93) * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment * devops: lhci results table comment (#94) * devops: debug lhci results comment * devops: debug lhci results comment (#95) * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment (#96) * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment * devops: debug lhci results comment * devops: lhci results table comment * devops: lhci results table comment * devops: debug lhci results comment * devops: lhci results table comment (#98) * chore: cleanup * devops: lhci results table comment * devops: test lhci results comment (#99) * devops: test lhci results comment * devops: test lhci results comment * devops: test lhci results comment * feat: shortener * feat: supabase auth * fix: hasura jwt secret on local env * fix: hasura jwt secret on local env * chore: user profile cookie * chore: user profile cookie * chore: user profile cookie * chore: user profile cookie * feat: supabase auth, github oauth, session cookies * devops: config pkgs, eslint, prettier, tailwind, ts (#101) * devops: config pkgs, eslint, prettier, tailwind, ts * devops: config pkgs, eslint, prettier, tailwind, ts * devops: config pkgs, eslint, prettier, tailwind, ts * devops: config pkgs, eslint, prettier, tailwind, ts * devops: remove first comment on lhci action * devops: fix eslint action * chore: ssr on browse, supa types, updated actions (#103) * chore: browse ssr improvements, supabase db types * chore: fix eslint * devops: lhci on pr * feat: thread ui dialog and ssr in public pages (#105) * feat: thread dialog ui * feat: thread dialog ui * feat: thread dialog ui * feat: ssr and layout improvements on u and b routes * fix: correct thread number * feat: ssr and layout improvements on u and b routes * feat: global categories nav * chore: move shared components * feat: copy shortlink * chore: disable getUserProfile * perf: only 25 items on first render * perf: only 20 items on first render * fix: supabase ssr bug (#106) * devops: wait 2 minutes before running lhci (#107) * feat: load only 15 more * fix: auth issues * devops: wait 2 minutes before running lhci * devops: wait before lhci, fix vercel build (#108) * feat: load only 15 more * fix: auth issues * devops: wait 2 minutes before running lhci * chore: cleanup * fix: header session bug * fix: chat auth bug (#109) * fix: chat auth bug * fix: chat auth bug * fix: chat auth bug * fix: chat navigation (#110) * fix: icon size * fix: chat navigation * feat: chat list and dialog (#111) * feat: chat lists and dialog * feat: chat lists and dialog * feat: dialog chat input
Summary by CodeRabbit
New Features
Refactor
supabase
client to improve backend communication efficiency.