Skip to content

Commit 835d62f

Browse files
authored
improve auth stability, support ssr auth, login redirects (#524)
* improve auth stability, support ssr auth, login redirects * drop expectAuth, causing issues
1 parent 5287e13 commit 835d62f

File tree

8 files changed

+169
-131
lines changed

8 files changed

+169
-131
lines changed

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@codemirror/lang-javascript": "^6.2.3",
2929
"@codemirror/lang-json": "^6.0.1",
3030
"@convex-dev/auth": "^0.0.88",
31-
"@convex-dev/better-auth": "0.9",
31+
"@convex-dev/better-auth": "0.9.7-alpha.0",
3232
"@convex-dev/react-query": "0.0.0-alpha.11",
3333
"@daytonaio/sdk": "^0.25.6",
3434
"@erquhart/convex-oss-stats": "^0.8.1",
@@ -49,12 +49,12 @@
4949
"@radix-ui/react-select": "^2.2.2",
5050
"@radix-ui/react-separator": "^1.1.0",
5151
"@radix-ui/react-slot": "^1.2.3",
52-
"@radix-ui/react-tooltip": "^1.1.5",
5352
"@radix-ui/react-switch": "^1.2.6",
5453
"@radix-ui/react-tabs": "^1.1.13",
5554
"@radix-ui/react-toast": "^1.2.2",
5655
"@radix-ui/react-toggle": "^1.1.10",
5756
"@radix-ui/react-toggle-group": "^1.1.11",
57+
"@radix-ui/react-tooltip": "^1.1.5",
5858
"@remix-run/node": "^2.8.1",
5959
"@sentry/react": "^8.35.0",
6060
"@sentry/vite-plugin": "^2.22.6",
@@ -89,8 +89,7 @@
8989
"class-variance-authority": "^0.7.1",
9090
"clsx": "^2.1.1",
9191
"cmdk": "^1.1.1",
92-
"convex": "^1.25.4",
93-
"convex-oss-stats": "link:../../../erquhart/convex-oss-stats",
92+
"convex": "^1.28.0",
9493
"cors": "^2.8.5",
9594
"d3": "^7.9.0",
9695
"date-fns": "^2.30.0",

pnpm-lock.yaml

Lines changed: 41 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Navbar.tsx

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@ import {
1616
} from 'react-icons/fa'
1717
import { ThemeToggle } from './ThemeToggle'
1818
import { SearchButton } from './SearchButton'
19-
import { Authenticated, Unauthenticated, useQuery } from 'convex/react'
20-
import { AuthLoading } from 'convex/react'
19+
import { Authenticated, useQuery } from 'convex/react'
2120
import { api } from 'convex/_generated/api'
2221
import { MdLibraryBooks, MdLineAxis, MdPerson, MdSupport } from 'react-icons/md'
2322
import { CgClose, CgMenuLeft, CgMusicSpeaker } from 'react-icons/cg'
2423
import { BiSolidCheckShield } from 'react-icons/bi'
2524
import { PiHammerFill, PiSparkleFill } from 'react-icons/pi'
2625
import { libraries } from '~/libraries'
2726
import { sortBy } from '~/utils/utils'
27+
import { convexQuery } from '@convex-dev/react-query'
28+
import { useSuspenseQuery } from '@tanstack/react-query'
2829

2930
export function Navbar({ children }: { children: React.ReactNode }) {
30-
const user = useQuery(api.auth.getCurrentUser)
31+
const { data: user } = useSuspenseQuery(
32+
convexQuery(api.auth.getCurrentUser, {})
33+
)
3134
const matches = useMatches()
3235

3336
const Title =
@@ -65,48 +68,40 @@ export function Navbar({ children }: { children: React.ReactNode }) {
6568

6669
const loginButton = (
6770
<>
68-
{(() => {
69-
const loginEl = (
70-
<Link
71-
to="/login"
72-
className="flex items-center gap-1 bg-gray-500/20 rounded-lg p-2 opacity-80
71+
{!user && (
72+
<Link
73+
to="/login"
74+
className="flex items-center gap-1 bg-gray-500/20 rounded-lg p-2 opacity-80
7375
hover:opacity-100 whitespace-nowrap uppercase font-black text-xs"
74-
>
75-
<MdPerson className="scale-125" />
76-
<div className="">Log In</div>
77-
</Link>
78-
)
79-
80-
return (
81-
<>
82-
<AuthLoading>{loginEl}</AuthLoading>
83-
<Unauthenticated>{loginEl}</Unauthenticated>
84-
</>
85-
)
86-
})()}
87-
88-
<Authenticated>
89-
<div className="flex items-center gap-2 px-2 py-1 rounded-lg">
90-
<FaUser />
91-
<Link
92-
to="/account"
93-
className="flex-1 text-sm font-medium text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white whitespace-nowrap"
94-
>
95-
My Account
96-
</Link>
97-
</div>
98-
{canAdmin ? (
76+
>
77+
<MdPerson className="scale-125" />
78+
<div className="">Log In</div>
79+
</Link>
80+
)}
81+
{user && (
82+
<>
9983
<div className="flex items-center gap-2 px-2 py-1 rounded-lg">
100-
<FaLock />
84+
<FaUser />
10185
<Link
102-
to="/admin"
103-
className="flex-1 text-sm font-medium text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white"
86+
to="/account"
87+
className="flex-1 text-sm font-medium text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white whitespace-nowrap"
10488
>
105-
Admin
89+
My Account
10690
</Link>
10791
</div>
108-
) : null}
109-
</Authenticated>
92+
{canAdmin && (
93+
<div className="flex items-center gap-2 px-2 py-1 rounded-lg">
94+
<FaLock />
95+
<Link
96+
to="/admin"
97+
className="flex-1 text-sm font-medium text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white"
98+
>
99+
Admin
100+
</Link>
101+
</div>
102+
)}
103+
</>
104+
)}
110105
</>
111106
)
112107

0 commit comments

Comments
 (0)