DaReal
DaReal•7mo ago

Convex Clerk Authentication

Hello guys! I have an issue with my Convex-Clerk Authentication. The issue is obvious during the sign in and sign up process when sending verification codes. The page loads twice therefore causing the otp to be sent 2x during sign-in and sign-up. This behaviour also occurs when a form is submitted. It reloads the page. Below is my code for ConvexClerkProvider.tsx "use client"; import Loading from "@/app/components/auth/Loading"; import { ClerkProvider, useAuth } from "@clerk/clerk-react"; import { AuthLoading, Authenticated, ConvexReactClient, Unauthenticated, } from "convex/react"; import { ConvexProviderWithClerk } from "convex/react-clerk"; type ConvexClerkProviderProps = { children: React.ReactNode; }; const clerkPublishableKey = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY; if (!clerkPublishableKey) { throw new Error("Missing Clerk Publishable Key"); } const convexUrl = process.env.NEXT_PUBLIC_CONVEX_URL!; const convex = new ConvexReactClient(convexUrl); const ConvexClerkProvider = ({ children }: ConvexClerkProviderProps) => { return ( <ClerkProvider publishableKey={clerkPublishableKey}> <ConvexProviderWithClerk client={convex} useAuth={useAuth}> <AuthLoading> <Loading /> </AuthLoading> <Authenticated>{children}</Authenticated> <Unauthenticated>{children}</Unauthenticated> </ConvexProviderWithClerk> </ClerkProvider> ); }; export default ConvexClerkProvider; Below is my layout structure: export default function RootLayout({ children, }: Readonly<{ children: React.ReactNode; }>) { return ( <html lang="en"> <body className={${inter.className}}> <ConvexClerkProvider> {children} <Toaster /> </ConvexClerkProvider> </body> </html> ); } Thanks in advance.
13 Replies
FleetAdmiralJakob 🗕 🗗 🗙
https://react.dev/reference/react/StrictMode Hi, this is completely normal react behaviour and should be dev mode only. But this shouldnt cause any issues.
– React
The library for web and native user interfaces
FleetAdmiralJakob 🗕 🗗 🗙
When forms are submitted it's normal too that the Page reloads. The event.preventDefault(); is key here
DaReal
DaRealOP•7mo ago
Yes i use this but the page reloading is a minor issue. This is where I am having issues because it's the same issue in production. My web app is currently in production and still exhibits the same issue
Michal Srb
Michal Srb•7mo ago
The page loads twice therefore causing the otp to be sent 2x during sign-in and sign-up.
I haven't used OTPs with Clerk, but I would assume Clerk does this after a button click, not on page load? Can you record a video of what's going on? (this could be also unrelated to Convex, in which case you can reach out to Clerk on their Discord)
DaReal
DaRealOP•7mo ago
After registeration...The code is sent 2x to both email and phone
No description
DaReal
DaRealOP•7mo ago
I thought so and i have also reached out to them on their Discord. But since I am using the ConvexClerkProvider, I thought it could be me doing something wrong with the ConvexClerkProvider which is why I opened a request here The AuthLoading state renders a loading component which basically shows a loader. During the registration, once the register button is clicked, the request is sent and then the loader appears which means the page refreshed. And then the code is otp request is resent again. return ( <ClerkProvider publishableKey={clerkPublishableKey}> <ConvexProviderWithClerk client={convex} useAuth={useAuth}> <AuthLoading> <Loading /> </AuthLoading> <Authenticated>{children}</Authenticated> <Unauthenticated>{children}</Unauthenticated> </ConvexProviderWithClerk> </ClerkProvider> );
Michal Srb
Michal Srb•7mo ago
I'd recommend removing Convex quickly, and checking whether you still have the same issue You can do that easily by replacing the AuthLoading etc. components with the ones exported from "@clerk/clerk-react"
DaReal
DaRealOP•7mo ago
DaReal
DaRealOP•7mo ago
Here is a video You will notice that the otp component is displayed shortly before the AuthLoading loader shows up and then renders the component again
FleetAdmiralJakob 🗕 🗗 🗙
Is this bug in the video with only using Clerk or Convex and Clerk?
DaReal
DaRealOP•7mo ago
I will confirm and let you know

Did you find this page helpful?