thedevstockgirl
thedevstockgirl7mo ago

Bug in Convex Auth: shouldHandleCode does not exist

Followed the docs to allow handling oauth flow for custom integrations. But it says this does not exist. Also, is the @convex-dev/react-query still maintained? Or should we be using something else. Primarily use this to get loading states for mutations and actions.
No description
No description
No description
No description
17 Replies
erquhart
erquhart7mo ago
Convex react query is still maintained, just no recent commits. 0.0.84 of convex auth was released specifically to address this, I’ll take a look as soon as I’m back to my machine. Right here: https://github.com/get-convex/convex-auth/blob/f9db58c8ee45ec528e168f792a1621459fd3224e/src/react/index.tsx#L93 I see the version confirmed in your screenshots, but is there any chance the actual running version is different?
thedevstockgirl
thedevstockgirlOP7mo ago
Our repo uses the same version all across. We specially use sheriff in our repo to ensure all apps and packages are using the same versions of any installed package. We run a postinstall job to actually enforce this. So there really is no chance of a different running version. The post install job does prompt you to choose a version to resolve if it detects a drift.
erquhart
erquhart6mo ago
Using a different component than ConvexAuthProvider specifically? Here's the types for that published version on unpkg: https://app.unpkg.com/@convex-dev/auth@0.0.84/files/dist/react/index.d.ts
UNPKG
The CDN for everything on npm
erquhart
erquhart6mo ago
The error there says only children and client are accepted, which doesn't match ConvexAuthProvider even before this prop was added.
thedevstockgirl
thedevstockgirlOP6mo ago
I am using the ConvexAuthNextjsProvider. Error still persists. Is it perhaps not available for this?
No description
No description
erquhart
erquhart6mo ago
Ah, it’s missing from the server provider still. Are you using ConvexAuthNextjsServerProvider in your root layout
thedevstockgirl
thedevstockgirlOP6mo ago
Yes.
Sara
Sara6mo ago
the component takes children+ client variables, you don't need the "should run code" definition
No description
erquhart
erquhart6mo ago
Yeah it wouldn't go there, it would go in the server provider, but this prop wasn't added there. Fixing now. @thedevstockgirl fixed in 0.0.87, you can add this prop to the server provider
thedevstockgirl
thedevstockgirlOP6mo ago
Thanks so much.
Tom Redman
Tom Redman3mo ago
@erquhart getting this error trying to use the shouldHandleCode in the server component:
// app/layout.tsx
<ConvexAuthNextjsServerProvider
shouldHandleCode={() => {
return location.pathname.startsWith("/integrations/connect");
}}
>
...
// app/layout.tsx
<ConvexAuthNextjsServerProvider
shouldHandleCode={() => {
return location.pathname.startsWith("/integrations/connect");
}}
>
...
Error:
Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Or maybe you meant to call this function rather than return it.
<... serverState={{...}} apiRoute=... storage=... storageNamespace=... shouldHandleCode={function shouldHandleCode} verbose=... children=...>
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Call Stack
6

Show 5 ignore-listed frame(s)
stringify
<anonymous>
Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Or maybe you meant to call this function rather than return it.
<... serverState={{...}} apiRoute=... storage=... storageNamespace=... shouldHandleCode={function shouldHandleCode} verbose=... children=...>
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Call Stack
6

Show 5 ignore-listed frame(s)
stringify
<anonymous>
erquhart
erquhart3mo ago
Yeah if you add "use server" at the top of the function I think it'll work, not sure if it's required to be at module root scope but I don't think so
<ConvexAuthNextjsServerProvider
shouldHandleCode={() => {
"use server"
return location.pathname.startsWith("/integrations/connect");
}}
>
<ConvexAuthNextjsServerProvider
shouldHandleCode={() => {
"use server"
return location.pathname.startsWith("/integrations/connect");
}}
>
Tom Redman
Tom Redman3mo ago
In this case it complains about needing to be an async function
Tom Redman
Tom Redman3mo ago
No description
Tom Redman
Tom Redman3mo ago
I'm using middleware to rewrite the search param for now
erquhart
erquhart3mo ago
Try 0.0.89, you can now pass a plain boolean instead of a function. You can also implement shouldHandleCode via middleware: https://labs.convex.dev/auth/advanced#nextjs-middleware
Tom Redman
Tom Redman3mo ago
Ah, didn't realize the middleware supplanted the React prop. Thanks man

Did you find this page helpful?