diff --git a/apps/database-new/app/LoginDialog.tsx b/apps/database-new/app/LoginDialog.tsx
new file mode 100644
index 00000000000..10d6f2fd26e
--- /dev/null
+++ b/apps/database-new/app/LoginDialog.tsx
@@ -0,0 +1,19 @@
+'use client'
+
+import { useAppStateSnapshot } from '@/lib/state'
+import { DialogContent_Shadcn_, Dialog_Shadcn_ } from 'ui'
+
+const LoginDialog = ({ children }: { children: React.ReactNode }) => {
+ const snap = useAppStateSnapshot()
+
+ return (
+ snap.setLoginDialogOpen(!snap.loginDialogOpen)}
+ >
+ {children}
+
+ )
+}
+
+export { LoginDialog }
diff --git a/apps/database-new/app/NewThreadInput.tsx b/apps/database-new/app/NewThreadInput.tsx
index ca63cbc3c60..a1a96dd2b81 100644
--- a/apps/database-new/app/NewThreadInput.tsx
+++ b/apps/database-new/app/NewThreadInput.tsx
@@ -1,9 +1,12 @@
'use client'
+
import { ChatInputAtom } from '@/components/Chat/ChatInput'
import { CHAT_EXAMPLES } from '@/data/chat-examples'
+import { useAppStateSnapshot } from '@/lib/state'
+import { createClient } from '@/lib/supabase/client'
import { useMutation } from '@tanstack/react-query'
import { ExternalLink } from 'lucide-react'
-import { useRouter } from 'next/navigation'
+import { useRouter, useSearchParams } from 'next/navigation'
import { useState } from 'react'
import { cn } from 'ui'
@@ -15,7 +18,21 @@ const suggestions = CHAT_EXAMPLES
const NewThreadInput = ({ userID }: ChatInputParams) => {
const router = useRouter()
- const [value, setValue] = useState('')
+
+ const [value, setValue] = useState(() => {
+ if (typeof window !== 'undefined') {
+ const localPrompt = localStorage.getItem('prompt')
+ if (localPrompt) {
+ localStorage.removeItem('prompt')
+ return localPrompt
+ }
+ }
+ return ''
+ })
+
+ const supabase = createClient()
+
+ const snap = useAppStateSnapshot()
const { mutate, isPending, isSuccess } = useMutation({
mutationFn: async (prompt: string) => {
@@ -39,8 +56,19 @@ const NewThreadInput = ({ userID }: ChatInputParams) => {
<>
{
- if (value.length > 0) mutate(value)
+ handleSubmit={async () => {
+ const {
+ data: { user },
+ } = await supabase.auth.getUser()
+
+ if (!user) {
+ localStorage.setItem('prompt', value)
+ snap.setLoginDialogOpen(true)
+ return
+ }
+ if (value.length > 0) {
+ mutate(value)
+ }
}}
autoFocus
value={value}
diff --git a/apps/database-new/app/login/page.tsx b/apps/database-new/app/login/page.tsx
index d4c9830477c..6e533b40daa 100644
--- a/apps/database-new/app/login/page.tsx
+++ b/apps/database-new/app/login/page.tsx
@@ -1,53 +1,5 @@
-import { createClient } from '@/lib/supabase/server'
-import { Github } from 'lucide-react'
-import { cookies, headers } from 'next/headers'
-import { redirect } from 'next/navigation'
+import LoginForm from '@/components/Auth/LoginForm'
export default function Login({ searchParams }: { searchParams: { message: string } }) {
- const signUp = async (formData: FormData) => {
- 'use server'
-
- const origin = headers().get('origin')
- const cookieStore = cookies()
- const supabase = createClient(cookieStore)
-
- const { data, error } = await supabase.auth.signInWithOAuth({
- provider: 'github',
- options: { redirectTo: `${origin}/auth/callback` },
- })
-
- if (error) {
- console.log(error.message)
- return redirect(`/login?message=${error.message}`)
- } else {
- return redirect(data.url)
- }
- }
-
- return (
-
- )
+ return
}
diff --git a/apps/database-new/app/page.tsx b/apps/database-new/app/page.tsx
index 598ff665fc6..5df1087258b 100644
--- a/apps/database-new/app/page.tsx
+++ b/apps/database-new/app/page.tsx
@@ -2,12 +2,18 @@ import { createClient } from '@/lib/supabase/server'
import type { Metadata } from 'next'
import { cookies } from 'next/headers'
import NewThreadInput from './NewThreadInput'
+import { LoginDialog } from './LoginDialog'
+import LoginForm from '@/components/Auth/LoginForm'
export const metadata: Metadata = {
title: 'database.design | Create',
}
-const NewThread = async () => {
+const NewThread = async ({
+ searchParams,
+}: {
+ searchParams: { prompt: string; message: string }
+}) => {
const cookieStore = cookies()
const supabase = createClient(cookieStore)
@@ -15,10 +21,17 @@ const NewThread = async () => {
data: { user },
} = await supabase.auth.getUser()
+ console.log('searchParams on page level', searchParams)
+
return (
-
-
-
+ <>
+
+
+
+
+
+
+ >
)
}
diff --git a/apps/database-new/components/Auth/LoginForm.tsx b/apps/database-new/components/Auth/LoginForm.tsx
new file mode 100644
index 00000000000..02849082c50
--- /dev/null
+++ b/apps/database-new/components/Auth/LoginForm.tsx
@@ -0,0 +1,63 @@
+import { createClient } from '@/lib/supabase/server'
+import { Github } from 'lucide-react'
+import { cookies, headers } from 'next/headers'
+import { redirect } from 'next/navigation'
+import { Button } from 'ui'
+
+export default function LoginForm({ searchParams }: { searchParams?: { message?: string } }) {
+ const signUp = async (formData: FormData) => {
+ 'use server'
+
+ const origin = headers().get('origin')
+ const cookieStore = cookies()
+ const supabase = createClient(cookieStore)
+
+ const { data, error } = await supabase.auth.signInWithOAuth({
+ provider: 'github',
+ options: { redirectTo: `${origin}/auth/callback` },
+ })
+
+ if (error) {
+ console.log(error.message)
+ return redirect(`/login?message=${error.message}`)
+ } else {
+ return redirect(data.url)
+ }
+ }
+
+ return (
+
+ )
+}
diff --git a/apps/database-new/lib/state.ts b/apps/database-new/lib/state.ts
index b30708ef8af..806341175e1 100644
--- a/apps/database-new/lib/state.ts
+++ b/apps/database-new/lib/state.ts
@@ -10,6 +10,11 @@ export const appState = proxy({
setSelectedCode: (value: string) => {
appState.selectedCode = value
},
+
+ loginDialogOpen: false,
+ setLoginDialogOpen: (value: boolean) => {
+ appState.loginDialogOpen = value
+ },
})
export const getAppStateSnapshot = () => snapshot(appState)
diff --git a/packages/ui/src/components/shadcn/ui/dialog.tsx b/packages/ui/src/components/shadcn/ui/dialog.tsx
index 80cf824f7a7..1b541a71cb8 100644
--- a/packages/ui/src/components/shadcn/ui/dialog.tsx
+++ b/packages/ui/src/components/shadcn/ui/dialog.tsx
@@ -1,3 +1,5 @@
+'use client'
+
import * as React from 'react'
import * as DialogPrimitive from '@radix-ui/react-dialog'
import { X } from 'lucide-react'