#Convex-test withIdentity fails for mutation inside mutation
1 messages · Page 1 of 1 (latest)
Hi @umbral burrow. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Short answer: only the top-level call gets the test identity. Nested Convex function calls don’t automatically inherit auth unless you pass it through or avoid calling public functions from other functions.
What you can do:
-
Refactor so public functions (with auth checks) call shared helpers, and only internal functions are invoked from other functions. Then the single top-level authed call is enough. [Best practices]
-
If you must invoke another function, make it internal and pass needed data (e.g., user id) as arguments instead of relying on ctx.auth in the nested call. [Scheduled auth note]
-
For tests, wrap the top-level call with t.withIdentity and ensure nested logic doesn’t perform another public mutation/query that expects ctx.auth; instead, call internal functions or helpers. [t.withIdentity]