Skip to content

Commit

Permalink
Make chats private and fix redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredpalmer committed Jun 16, 2023
1 parent 37609dc commit 3c71b36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/chat/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default async function ChatPage({ params }: ChatPageProps) {
const session = await auth()

if (!session?.user) {
redirect('/sign-in')
redirect(`/sign-in?next=/chat/${params.id}`)
}

const chat = await getChat(params.id, session.user.id)
Expand All @@ -42,5 +42,9 @@ export default async function ChatPage({ params }: ChatPageProps) {
notFound()
}

if (chat?.userId !== session?.user?.id) {
notFound()
}

return <Chat id={chat.id} initialMessages={chat.messages} />
}
9 changes: 7 additions & 2 deletions components/login-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { signIn } from 'next-auth/react'
import { cn } from '@/lib/utils'
import { Button, type ButtonProps } from '@/components/ui/button'
import { IconGitHub, IconSpinner } from '@/components/ui/icons'

import { useSearchParams } from 'next/navigation'
interface LoginButtonProps extends ButtonProps {
showGithubIcon?: boolean
text?: string
Expand All @@ -19,13 +19,18 @@ export function LoginButton({
...props
}: LoginButtonProps) {
const [isLoading, setIsLoading] = React.useState(false)
const searchParams = useSearchParams()
const next = searchParams.get('next')

return (
<Button
variant="outline"
onClick={() => {
setIsLoading(true)
signIn('github')
signIn('github', {
callbackUrl: `${window.location.origin}${next}`,
redirect: true
})
}}
disabled={isLoading}
className={cn(className)}
Expand Down

0 comments on commit 3c71b36

Please sign in to comment.