-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,14 +11,15 @@ export default async function ChatPage({ params }: ChatPageProps) { | |||||
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}/${params.threadId}`) | ||||||
const jwt = cookies().get('hasuraJwt')?.value || '' | ||||||
|
||||||
console.log({ jwt, expired: isTokenExpired(jwt), user }) | ||||||
// NOTE: maybe we should use same expiration time | ||||||
if (!jwt || isTokenExpired(jwt) || !user) | ||||||
redirect(`/auth/sign-in?next=/${params.threadId}/${params.threadId}`) | ||||||
redirect(`/auth/sign-in?next=/${params.chatbot}/${params.threadId}`) | ||||||
|
||||||
Comment on lines
+21
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure proper handling of asynchronous - 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 Committable suggestion
Suggested change
|
||||||
const thread = await getThread({ | ||||||
threadId: params.threadId | ||||||
}) | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Ensure proper handling of asynchronous - if (!user || !user.email) redirect(`/auth/sign-in?next=/${params.chatbot}`)
+ if (!user || !user.email) return redirect(`/auth/sign-in?next=/${params.chatbot}`) The Committable suggestion
Suggested change
|
||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Ensure proper handling of asynchronous - 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 Committable suggestion
Suggested change
|
||||||||
const jwt = cookies().get('hasuraJwt')?.value || '' | ||||||||
|
||||||||
// NOTE: maybe we should use same expiration time | ||||||||
if (!jwt || isTokenExpired(jwt) || !user) redirect(`/auth/sign-in?next=/c`) | ||||||||
if (!jwt || isTokenExpired(jwt)) | ||||||||
redirect(`/auth/sign-in?next=/${params.chatbot}`) | ||||||||
Comment on lines
+33
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure proper handling of asynchronous - if (!jwt || isTokenExpired(jwt))
- redirect(`/auth/sign-in?next=/${params.chatbot}`)
+ if (!jwt || isTokenExpired(jwt)) return redirect(`/auth/sign-in?next=/${params.chatbot}`) The Committable suggestion
Suggested change
|
||||||||
const chatbot = await getChatbot({ | ||||||||
chatbotName: botNames.get(params.chatbot), | ||||||||
jwt | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Ensure proper handling of asynchronous - if (!user || !user.email) redirect(`/auth/sign-in`)
+ if (!user || !user.email) return redirect(`/auth/sign-in`) The Committable suggestion
Suggested change
|
||||||
|
||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Ensure proper handling of asynchronous - if (!dbUserProfile) redirect(`/auth/sign-in`)
+ if (!dbUserProfile) return redirect(`/auth/sign-in`) Similar to the previous comment, the Committable suggestion
Suggested change
|
||||||
|
||||||
const jwt = cookies().get('hasuraJwt').value || '' | ||||||
|
||||||
|
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.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