Make chats private and fix redirection
This commit is contained in:
parent
37609dce7e
commit
3c71b3679a
2 changed files with 12 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
@ -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} />
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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)}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue