StiffJobs
StiffJobs2mo ago

ConvexAuth error when shouldHandleCode is false

function InnerApp() {
const { isAuthenticated, isLoading } = useConvexAuth();
const locale = window.localStorage.getItem('locale') || 'zh';
useEffect(() => {
dynamicActivate(locale);
}, [locale]);
useEffect(() => {
console.log('isloading?:', isLoading);
}, [isLoading]);

if (isLoading) {
return (
<div className="min-h-screen flex items-center justify-center">
<div className="text-sm text-gray-500">Loading…</div>
</div>
);
}

return (
<I18nProvider i18n={i18n}>
<RouterProvider
router={router}
context={{
queryClient,
isAuthenticated,
}}
/>
</I18nProvider>
);
}
const rootElement = document.getElementById('app');
if (rootElement && !rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement);
root.render(
<StrictMode>
<ConvexAuthProvider
client={convex}
shouldHandleCode={() => {
console.log('path', location.pathname);
if (location.pathname.startsWith('/accounts')) {
console.log('here');
return false;
}
return true;
}}
>
<QueryClientProvider client={queryClient}>
<InnerApp />
</QueryClientProvider>
</ConvexAuthProvider>
</StrictMode>,
);
}
function InnerApp() {
const { isAuthenticated, isLoading } = useConvexAuth();
const locale = window.localStorage.getItem('locale') || 'zh';
useEffect(() => {
dynamicActivate(locale);
}, [locale]);
useEffect(() => {
console.log('isloading?:', isLoading);
}, [isLoading]);

if (isLoading) {
return (
<div className="min-h-screen flex items-center justify-center">
<div className="text-sm text-gray-500">Loading…</div>
</div>
);
}

return (
<I18nProvider i18n={i18n}>
<RouterProvider
router={router}
context={{
queryClient,
isAuthenticated,
}}
/>
</I18nProvider>
);
}
const rootElement = document.getElementById('app');
if (rootElement && !rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement);
root.render(
<StrictMode>
<ConvexAuthProvider
client={convex}
shouldHandleCode={() => {
console.log('path', location.pathname);
if (location.pathname.startsWith('/accounts')) {
console.log('here');
return false;
}
return true;
}}
>
<QueryClientProvider client={queryClient}>
<InnerApp />
</QueryClientProvider>
</ConvexAuthProvider>
</StrictMode>,
);
}
when trying to ignore the handle code for some path in my tanstack router app, the isLoading state from the useConvexAuth keep staying true. Don't know why this happened.
10 Replies
Convex Bot
Convex Bot2mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
erquhart
erquhart2mo ago
Is the code you're ignoring related to auth? Sounds like when the code is ignored auth is being held up, but that's mostly a guess based on the description
StiffJobs
StiffJobsOP2mo ago
I'm using Tanstack router and there's a _auth.tsx as a layout file for my /accounts path, and in the _auth.tsx will check whether isAuthenticated from the useConvexAuth, but even if i set the shouldHandleCode to false on the /accounts, everytime I add code param to the path, it would redirect me back to the /
erquhart
erquhart2mo ago
Eg., it logs "here" (based on the code sample) but still redirects to root?
StiffJobs
StiffJobsOP2mo ago
Yes It seems like the code param still trigger the remove session or something that will make isaithenticated to false even with the shouldhandlecode to false
erquhart
erquhart2mo ago
Can you try installing @convex-dev/auth@alpha and see if that solves it should be 0.0.90-alpha.0
StiffJobs
StiffJobsOP2mo ago
It works Wow what just happened the 0.0.90-alpha.0 actually works
erquhart
erquhart2mo ago
awesome - shouldHandleCode in the client had a bug in the conditional handling will promote to 0.0.90, thanks for validating
StiffJobs
StiffJobsOP2mo ago
Ic Huge thanks for this @erquhart
erquhart
erquhart2mo ago
Promoted to latest, 0.0.90

Did you find this page helpful?