Skip to content

Commit

Permalink
fix: chat auth bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gaboesquivel committed Apr 8, 2024
1 parent f127889 commit 7caa6e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions apps/masterbots.ai/app/c/[chatbot]/[threadId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ export default async function ChatPage({ params }: ChatPageProps) {
const {
data: { user }
} = await supabase.auth.getUser()
if (!user || !user.email) redirect(`/auth/sign-in`)

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}`)

const thread = await getThread({
threadId: params.threadId
})
Expand Down
7 changes: 4 additions & 3 deletions apps/masterbots.ai/app/c/[chatbot]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ export default async function BotThreadsPage({
const {
data: { user }
} = await supabase.auth.getUser()
if (!user || !user.email) redirect(`/auth/sign-in`)
if (!user || !user.email) redirect(`/auth/sign-in?next=/${params.chatbot}`)
const userProfile = await getUser({
email: user.email,
adminSecret: process.env.HASURA_GRAPHQL_ADMIN_SECRET || ''
})

if (!userProfile) redirect(`/auth/sign-in`)
if (!userProfile) redirect(`/auth/sign-in?next=/${params.chatbot}`)
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}`)
const chatbot = await getChatbot({
chatbotName: botNames.get(params.chatbot),
jwt
Expand Down

0 comments on commit 7caa6e2

Please sign in to comment.