MCPcopy Create free account
hub / github.com/TanStack/db / AuthenticatedLayout

Function AuthenticatedLayout

examples/react/projects/src/routes/_authenticated.tsx:17–150  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15})
16
17function AuthenticatedLayout() {
18 const { data: session, isPending } = authClient.useSession()
19 const navigate = useNavigate()
20 const [showNewProjectForm, setShowNewProjectForm] = useState(false)
21 const [newProjectName, setNewProjectName] = useState(``)
22
23 const { data: projects } = useLiveQuery((q) => q.from({ projectCollection }))
24
25 const handleLogout = async () => {
26 await authClient.signOut()
27 navigate({ to: `/login` })
28 }
29
30 const handleCreateProject = () => {
31 if (newProjectName.trim() && session) {
32 projectCollection.insert({
33 id: Math.floor(Math.random() * 100000),
34 name: newProjectName.trim(),
35 description: ``,
36 owner_id: session.user.id,
37 shared_user_ids: [],
38 created_at: new Date(),
39 updated_at: new Date(),
40 })
41 setNewProjectName(``)
42 setShowNewProjectForm(false)
43 }
44 }
45
46 if (isPending) {
47 return null
48 }
49
50 if (!session) {
51 return null
52 }
53
54 return (
55 <div className="min-h-screen bg-gray-50">
56 <header className="bg-white shadow border-b border-gray-200">
57 <div className="max-w-7xl mx-auto px-3 sm:px-6 lg:px-8">
58 <div className="flex justify-between items-center h-16">
59 <div className="flex-shrink-0">
60 <h1 className="text-xl font-semibold text-gray-900">
61 TanStack DB Projects Example
62 </h1>
63 </div>
64 <div className="flex items-center space-x-4">
65 <span className="text-sm text-gray-700">
66 {session.user.email}
67 </span>
68 <button
69 onClick={handleLogout}
70 className="text-sm font-medium text-gray-700 hover:text-gray-900 px-3 py-2 rounded-md hover:bg-gray-100 transition-colors"
71 >
72 Sign out
73 </button>
74 </div>

Callers

nothing calls this directly

Calls 5

useLiveQueryFunction · 0.90
handleCreateProjectFunction · 0.85
fromMethod · 0.80
mapMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected