@@ -30,6 +30,7 @@ import { downloadFile, titleToKebabCase } from '~/lib/util'
3030import { cn } from '~/lib/utils'
3131import { useApp } from './app-provider'
3232import { CodeBlock } from './code-block'
33+ import SignInButton from './sign-in-button'
3334import ThemeDropdown from './theme-dropdown'
3435import {
3536 DropdownMenu ,
@@ -40,14 +41,45 @@ import {
4041} from './ui/dropdown-menu'
4142
4243export default function Sidebar ( ) {
43- const { user, signOut, focusRef } = useApp ( )
44+ const { user, signOut, focusRef, isSignInDialogOpen , setIsSignInDialogOpen } = useApp ( )
4445 let { id : currentDatabaseId } = useParams < { id : string } > ( )
4546 const router = useRouter ( )
4647 const { data : databases , isLoading : isLoadingDatabases } = useDatabasesQuery ( )
4748 const [ showSidebar , setShowSidebar ] = useState ( true )
4849
4950 return (
5051 < >
52+ < Dialog
53+ open = { isSignInDialogOpen }
54+ onOpenChange = { ( open ) => {
55+ setIsSignInDialogOpen ( open )
56+ } }
57+ >
58+ < DialogContent className = "max-w-2xl" >
59+ < DialogHeader >
60+ < DialogTitle > Sign in to create a database</ DialogTitle >
61+ < div className = "py-2 border-b" />
62+ </ DialogHeader >
63+ < h2 className = "font-bold" > Why do I need to sign in?</ h2 >
64+ < p >
65+ Even though your Postgres databases run{ ' ' }
66+ < a
67+ className = "underline"
68+ href = "https://pglite.dev"
69+ target = "_blank"
70+ rel = "noopener noreferrer"
71+ >
72+ directly in the browser
73+ </ a >
74+ , we still need to connect to an API that runs the large language model (required for
75+ all database interactions).
76+ </ p >
77+ < p > We ask you to sign in to prevent API abuse.</ p >
78+ < div className = "flex justify-center items-center my-3" >
79+ < SignInButton />
80+ </ div >
81+ </ DialogContent >
82+ </ Dialog >
5183 < AnimatePresence initial = { false } mode = "popLayout" >
5284 { showSidebar && (
5385 < m . div
@@ -83,8 +115,12 @@ export default function Sidebar() {
83115 < m . div layout = "position" layoutId = "new-database-button" >
84116 < Button
85117 onClick = { ( ) => {
86- router . push ( '/' )
87- focusRef . current ?. focus ( )
118+ if ( ! user ) {
119+ setIsSignInDialogOpen ( true )
120+ } else {
121+ router . push ( '/' )
122+ focusRef . current ?. focus ( )
123+ }
88124 } }
89125 className = "gap-2"
90126 >
@@ -176,8 +212,12 @@ export default function Sidebar() {
176212 < Button
177213 size = { 'icon' }
178214 onClick = { ( ) => {
179- router . push ( '/' )
180- focusRef . current ?. focus ( )
215+ if ( ! user ) {
216+ setIsSignInDialogOpen ( true )
217+ } else {
218+ router . push ( '/' )
219+ focusRef . current ?. focus ( )
220+ }
181221 } }
182222 >
183223 < PackagePlus size = { 14 } />
@@ -201,24 +241,24 @@ export default function Sidebar() {
201241 </ TooltipContent >
202242 </ Tooltip >
203243 { user && (
204- < Tooltip >
205- < TooltipTrigger asChild >
206- < m . div layout = "position" layoutId = "sign-out-button" >
207- < Button
208- size = { 'icon' }
209- variant = "secondary"
210- onClick = { async ( ) => {
211- await signOut ( )
212- } }
213- >
214- < LogOut size = { 16 } strokeWidth = { 2 } />
215- </ Button >
216- </ m . div >
217- </ TooltipTrigger >
218- < TooltipContent side = "right" >
219- < p > Sign out</ p >
220- </ TooltipContent >
221- </ Tooltip >
244+ < Tooltip >
245+ < TooltipTrigger asChild >
246+ < m . div layout = "position" layoutId = "sign-out-button" >
247+ < Button
248+ size = { 'icon' }
249+ variant = "secondary"
250+ onClick = { async ( ) => {
251+ await signOut ( )
252+ } }
253+ >
254+ < LogOut size = { 16 } strokeWidth = { 2 } />
255+ </ Button >
256+ </ m . div >
257+ </ TooltipTrigger >
258+ < TooltipContent side = "right" >
259+ < p > Sign out</ p >
260+ </ TooltipContent >
261+ </ Tooltip >
222262 ) }
223263 </ div >
224264 </ div >
@@ -258,7 +298,7 @@ function DatabaseMenuItem({ database, isActive }: DatabaseMenuItemProps) {
258298 < DialogTitle > Deployments are in Private Alpha</ DialogTitle >
259299 < div className = "py-2 border-b" />
260300 </ DialogHeader >
261- < h2 className = "font-medium " > What are deployments?</ h2 >
301+ < h2 className = "font-bold " > What are deployments?</ h2 >
262302 < p >
263303 Deploy your database to a serverless PGlite instance so that it can be accessed outside
264304 the browser using any Postgres client:
0 commit comments