karlosK
Convex Community2mo ago
1 reply
karlos

(Convex Auth) Uncaught Error: InvalidKey

Hi,

I’m using Convex Auth with a custom Password provider and a React hook to handle sign-in. My backend code looks like this:

export const { auth, signIn, signOut, store, isAuthenticated } = convexAuth({
  providers: [
    Password<DataModel>({
      id: "password",
      profile: (params) => ({
        email: params.email as string,
        name: params.name as string,
        role: params.role as string,
      }),
      crypto: {
        verifySecret: async (secret, hash) => {
          if (secret === hash) return true;
          throw new ConvexError({ code: 401, message: "[BLL] Invalid credentials" });
        },
        hashSecret: async (secret) => secret,
      },
    }),
  ],
});


And my React hook is:

export const useAuth = () => {
  const { signIn } = useAuthActions();
  const [loading, setLoading] = useState(false);
  const [error, setError] = useState<string | undefined>();

  const handleAuth = async ({ email, password, flow, name, role }: HandleAuth) => {
    setLoading(true);
    signIn("password", { email, password, name: name ?? "", role: role ?? "", flow })
      .then(() => router.replace("/(tabs)/home"))
      .catch((error: Error) => {
        const errorMessage =
          error instanceof ConvexError ? error.data.message : error.message;
        setError(errorMessage);
      })
      .finally(() => setLoading(false));
  };

  return { loading, error, handleAuth, setError };
};


I’m catching errors inside the hook and updating state, but the Convex backend logs show uncaught ConvexError:

[CONVEX M(auth:store)] Uncaught ConvexError: {"code":401,"message":"[BLL] Invalid credentials"}
[CONVEX A(auth:signIn)] Uncaught ConvexError: Uncaught ConvexError: {"code":401,"message":"[BLL] Invalid credentials"}


The error is thrown inside verifySecret. My question:

* Is it normal for Convex server to log errors as uncaught even if I catch them on the client?

Thanks in advance for any guidance!
Screenshot_2025-11-15_at_11.22.20_PM.png
Was this page helpful?