THEO
THEO7d ago

Clerk integration call functions infinitely - need help

Using expo@52.0.17, convex@1.17.3 and @clerk/clerk-expo@2.4.2, currently working in a turborepo project with yarn I have configured the clerk integration according to the documentation, my _layout.tsx :
import { ClerkProvider, useAuth, ClerkLoaded } from "@clerk/clerk-expo";
import { ConvexProviderWithClerk } from "convex/react-clerk";
import { ConvexReactClient } from "convex/react";
const convex = new ConvexReactClient(
process.env.EXPO_PUBLIC_CONVEX_URL as string,
);

const tokenCache = {
async getToken(key: string) {
try {
const item = await SecureStore.getItemAsync(key);
if (item) {
console.log(`${key} was used 🔐 \n`); // this log gets printed infinitetly
} else {
console.log("No values stored under key: " + key);
}
return item;
} catch (error) {
console.error("SecureStore get item error: ", error);
await SecureStore.deleteItemAsync(key);
return null;
}
},
async saveToken(key: string, value: string) {
try {
return SecureStore.setItemAsync(key, value);
} catch (err) {
console.error("SecureStore set item error: ", err);
return;
}
},
};

export default function RootLayout() {
return (
<ClerkProvider
publishableKey={process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY as string}
tokenCache={tokenCache}
>
<ClerkLoaded>
<ConvexProviderWithClerk client={convex} useAuth={useAuth}>
<Stack />
</ConvexProviderWithClerk>
</ClerkLoaded>
</ClerkProvider>
)
}
import { ClerkProvider, useAuth, ClerkLoaded } from "@clerk/clerk-expo";
import { ConvexProviderWithClerk } from "convex/react-clerk";
import { ConvexReactClient } from "convex/react";
const convex = new ConvexReactClient(
process.env.EXPO_PUBLIC_CONVEX_URL as string,
);

const tokenCache = {
async getToken(key: string) {
try {
const item = await SecureStore.getItemAsync(key);
if (item) {
console.log(`${key} was used 🔐 \n`); // this log gets printed infinitetly
} else {
console.log("No values stored under key: " + key);
}
return item;
} catch (error) {
console.error("SecureStore get item error: ", error);
await SecureStore.deleteItemAsync(key);
return null;
}
},
async saveToken(key: string, value: string) {
try {
return SecureStore.setItemAsync(key, value);
} catch (err) {
console.error("SecureStore set item error: ", err);
return;
}
},
};

export default function RootLayout() {
return (
<ClerkProvider
publishableKey={process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY as string}
tokenCache={tokenCache}
>
<ClerkLoaded>
<ConvexProviderWithClerk client={convex} useAuth={useAuth}>
<Stack />
</ConvexProviderWithClerk>
</ClerkLoaded>
</ClerkProvider>
)
}
when i authenticate a user in my app the terminal gets flooded with console logs and in the convex logs, my functions are getting invoked infinitely as well as far as i could debug, the problem has its origin in convex, since i tested this in a freshly created clerk application and the error still happens
No description
10 Replies
erquhart
erquhart7d ago
I wonder if <ClerkLoaded> is causing an issue. I believe the <ConvexProviderWithClerk> takes care of that concern for you. Don't know if that's actually causing a problem, though.
THEO
THEOOP7d ago
Just tried removing <ClerkLoaed> The problem persist
sshader
sshader6d ago
Does the problem happen on Convex 1.17.2 (or any older version)? Per the changelog 1.17.3 includes a change in the Convex library around the memoization of clerk's getToken function, but we perhaps didn't account for clerk-expo here
GitHub
convex-js/CHANGELOG.md at main · get-convex/convex-js
TypeScript/JavaScript client library for Convex. Contribute to get-convex/convex-js development by creating an account on GitHub.
THEO
THEOOP6d ago
moving down to 1.17.2 didn't resolve the issue, but downgrading to 1.16.5 did might be some missconfiguration on my end, but for now is working as expected
ballingt
ballingt6d ago
@THEO could you try upgrading to 1.17.2 again, just in case this was a issue with something not reloading? Looking through changes this could make sense for the change sshader points out above but there's nothing else obvious that cause cause this.
THEO
THEOOP6d ago
i will try in an hour or 2 and comment on the results, since I had to go out for lunch @ballingt It works now i tried upgrading one release at a time until 1.17.2 just to make sure, and the logs didn't appear unlike 1.17.3
ballingt
ballingt6d ago
thank you for checking, we'll have this fixed in the next release soon
Sronds
Sronds5d ago
just ran into this bug myself! thanks
ballingt
ballingt5d ago
This should be fixed in convex@1.17.4, just published @Sronds @THEO
Sronds
Sronds5d ago
thanks team, good work! ❤️❤️