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()
|
const session = await auth()
|
||||||
|
|
||||||
if (!session?.user) {
|
if (!session?.user) {
|
||||||
redirect('/sign-in')
|
redirect(`/sign-in?next=/chat/${params.id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const chat = await getChat(params.id, session.user.id)
|
const chat = await getChat(params.id, session.user.id)
|
||||||
|
|
@ -42,5 +42,9 @@ export default async function ChatPage({ params }: ChatPageProps) {
|
||||||
notFound()
|
notFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chat?.userId !== session?.user?.id) {
|
||||||
|
notFound()
|
||||||
|
}
|
||||||
|
|
||||||
return <Chat id={chat.id} initialMessages={chat.messages} />
|
return <Chat id={chat.id} initialMessages={chat.messages} />
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { signIn } from 'next-auth/react'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import { Button, type ButtonProps } from '@/components/ui/button'
|
import { Button, type ButtonProps } from '@/components/ui/button'
|
||||||
import { IconGitHub, IconSpinner } from '@/components/ui/icons'
|
import { IconGitHub, IconSpinner } from '@/components/ui/icons'
|
||||||
|
import { useSearchParams } from 'next/navigation'
|
||||||
interface LoginButtonProps extends ButtonProps {
|
interface LoginButtonProps extends ButtonProps {
|
||||||
showGithubIcon?: boolean
|
showGithubIcon?: boolean
|
||||||
text?: string
|
text?: string
|
||||||
|
|
@ -19,13 +19,18 @@ export function LoginButton({
|
||||||
...props
|
...props
|
||||||
}: LoginButtonProps) {
|
}: LoginButtonProps) {
|
||||||
const [isLoading, setIsLoading] = React.useState(false)
|
const [isLoading, setIsLoading] = React.useState(false)
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const next = searchParams.get('next')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
signIn('github')
|
signIn('github', {
|
||||||
|
callbackUrl: `${window.location.origin}${next}`,
|
||||||
|
redirect: true
|
||||||
|
})
|
||||||
}}
|
}}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
className={cn(className)}
|
className={cn(className)}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue