17 Replies
I keep seeing the auth state refresh as I change routtes
the trick was to use clerk useAuth directly and not use the convex one

@Web Dev Cody do you have
ConvexProvider
wrapped around <RemixBrowser />
in entry.client.tsx
? Otherwise I'd be worried that the Provider gets reinitialized on every route transition.I thought the proper place to put providers was in the root file
a remix quick start guide might be nice
@Web Dev Cody here's an example repo:
https://github.com/xixixao/convex-clerk-remix
Changes:
1. I followed the Clerk Remix guide, that way you get Clerk on the server (SSR) as well
2. You need to memoize the ConvexClient, otherwise you'll get a new one every time the root renders
I'll also add isomorphic Convex API to another branch on the repo later. I think you'd really love this, based on your last video. It will give you data from Convex during SSR. Code once, get both server-side rendered and client-side rendered pages, without any changes to your code! 😇
GitHub
GitHub - xixixao/convex-clerk-remix: Example of Convex app with Cle...
Example of Convex app with Clerk and Remix. Contribute to xixixao/convex-clerk-remix development by creating an account on GitHub.
ahh ok I think that was the key part I was missing
const convex = useMemo(() => new ConvexReactClient(CONVEX_URL), [CONVEX_URL]);
thank you!
actually, @Michal Srb how did you get this working without using
<ClerkProvider publishableKey={data.ENV.CLERK_PUBLISHABLE_KEY!}>
mine just crashes when I remove the <ClerkProvider>
ok so the issue is with my header
for some reason having these cause my remix app to crash with

if I comment them out of my header it works fine
@Web Dev Cody I followed the Clerk guide, so I have:
1. rootAuthLoader in the root.tsx loader
2. export default ClerkApp(App);
3. export const ErrorBoundary = V2_ClerkErrorBoundary();
https://github.com/xixixao/convex-clerk-remix/blob/master/app/root.tsx
GitHub
convex-clerk-remix/app/root.tsx at master · xixixao/convex-clerk-re...
Example of Convex app with Clerk and Remix. Contribute to xixixao/convex-clerk-remix development by creating an account on GitHub.
try bringing in a <SignInButton> from clerk
I'm pretty sure it'll crash
oh wait
you have <SignIn
I'm using <SignInButton
ok that was the issue, I'm importing the same named components from a different package 🤯
I have setup the sign in and sign up as per here:
https://clerk.com/docs/quickstarts/remix#use-clerk-with-remix
Now when I add
<SignInButton />
<SignOutButton />
to _index route they work as well (I'll push this)
Use Clerk with Remix | Clerk
Learn how to use Clerk to quickly and easily add secure authentication and user management to your Remix application.
For future reference, this is an example of SignInButton use:
https://github.com/xixixao/convex-clerk-remix/blob/master/app/routes/_index.tsx#L14-L27
GitHub
convex-clerk-remix/app/routes/_index.tsx at master · xixixao/convex...
Example of Convex app with Clerk and Remix. Contribute to xixixao/convex-clerk-remix development by creating an account on GitHub.
nice, ty!
Hey @Web Dev Cody just came across your issue, I think putting constructor call
new ConvexReactClient(CONVEX_URL)
inside a react component create a new reference of the object each time on each re-render. useMemo works but I think taking it outside of the react component would be better and no need useMemo 🙂@Amix that's what we usually suggest, but it's not possible in Remix because Remix doesn't inject environment variables into the client source code (unfortunately, unlike Vite/Next).
opsss -1 point for Remix 🙂