oscklm
oscklm5mo ago

[ConvexAuth] Convex 1.14 seems to break ConvexAuthProvider token storage

Just had a issue where tokens weren't picked up by ConvexAuthProvider, after upgrading to Convex 1.14, going back to 1.13.2 fixed the issue, and saved jwt tokens were loaded as expected. Let me know if more info is needed
3 Replies
Michal Srb
Michal Srb5mo ago
I cannot repro. Can you try again and see if you get any errors?
oscklm
oscklmOP5mo ago
Yeah sure i'll give it a go Still happening. I'll try and troubleshoot some more later, and report back. In case i don't find some cause, ill make a repro and send it ur way. Im unsure why switching back to 1.13.2 fixes the issue. But this is the client provider for reference:
import { ConvexAuthProvider } from '@convex-dev/auth/react';
import { ConvexReactClient } from 'convex/react';
import * as SecureStore from 'expo-secure-store';
const convex = new ConvexReactClient(process.env.EXPO_PUBLIC_CONVEX_URL);

const enableLogging = __DEV__;

const secureStorage = {
getItem: async (key: string) => {
try {
const value = await SecureStore.getItemAsync(key);
if (enableLogging) {
console.log(`SecureStore.getItemAsync - Key: ${key}, Value: ${value}`);
}
return value;
} catch (error) {
if (enableLogging) {
console.error(`Error getting item with key ${key}`, error);
}
throw error;
}
},
setItem: async (key: string, value: string) => {
try {
await SecureStore.setItemAsync(key, value);
if (enableLogging) {
console.log(`SecureStore.setItemAsync - Key: ${key}, Value: ${value}`);
}
} catch (error) {
if (enableLogging) {
console.error(`Error setting item with key ${key}`, error);
}
throw error;
}
},
removeItem: async (key: string) => {
try {
await SecureStore.deleteItemAsync(key);
if (enableLogging) {
console.log(`SecureStore.deleteItemAsync - Key: ${key}`);
}
} catch (error) {
if (enableLogging) {
console.error(`Error removing item with key ${key}`, error);
}
throw error;
}
},
};

export default function ConvexClientProvider({ children }: { children: React.ReactNode }) {
return (
<ConvexAuthProvider storage={secureStorage} client={convex}>
{children}
</ConvexAuthProvider>
);
}
import { ConvexAuthProvider } from '@convex-dev/auth/react';
import { ConvexReactClient } from 'convex/react';
import * as SecureStore from 'expo-secure-store';
const convex = new ConvexReactClient(process.env.EXPO_PUBLIC_CONVEX_URL);

const enableLogging = __DEV__;

const secureStorage = {
getItem: async (key: string) => {
try {
const value = await SecureStore.getItemAsync(key);
if (enableLogging) {
console.log(`SecureStore.getItemAsync - Key: ${key}, Value: ${value}`);
}
return value;
} catch (error) {
if (enableLogging) {
console.error(`Error getting item with key ${key}`, error);
}
throw error;
}
},
setItem: async (key: string, value: string) => {
try {
await SecureStore.setItemAsync(key, value);
if (enableLogging) {
console.log(`SecureStore.setItemAsync - Key: ${key}, Value: ${value}`);
}
} catch (error) {
if (enableLogging) {
console.error(`Error setting item with key ${key}`, error);
}
throw error;
}
},
removeItem: async (key: string) => {
try {
await SecureStore.deleteItemAsync(key);
if (enableLogging) {
console.log(`SecureStore.deleteItemAsync - Key: ${key}`);
}
} catch (error) {
if (enableLogging) {
console.error(`Error removing item with key ${key}`, error);
}
throw error;
}
},
};

export default function ConvexClientProvider({ children }: { children: React.ReactNode }) {
return (
<ConvexAuthProvider storage={secureStorage} client={convex}>
{children}
</ConvexAuthProvider>
);
}
I've tried removing / disabling the logging behaviour i have wrapped the secureStorage functionality in. But had no effect on the issue I failed to add to my original message that this is in react native, with expo secure store. I have tried the following Switching back and forth again between convex 1.13.2 and 1.14.0, with @convex-dev/auth 0.0.47 and the same issues between the those persists, with the token storage not getting correctly, thus never authenticating the user even though the token is actually there in expo secure store But now, even after switching back to what worked with convex 1.13.2 a new issue has returned, which i have had previously seemed this ERROR Auth token is not a valid JWT, cannot refetch the token and i have tried most of the most common things (wiping node_modules & yarn lock) no logic thouching JWT's etc. has been touched, at least to my understanding. I'm gonna leave this here, and revisit this with a fresh set of eyes tomorrow. It's not a blocking issue, with the error saying the jwt auth token isnt valid luckily
Julián David
Julián David4mo ago
I'm encountering the same error after moving my project to a monorepo with Turborepo Quick update: Using pnpm instead of yarn fixes the error :fixed:

Did you find this page helpful?