THEOT
Convex Community14mo ago
11 replies
THEO

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>
  )
}

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
F9643F1C-6D8F-4753-823D-61A914C3D007.png
Was this page helpful?