User not authenticated" error in Convex mutation when called from Next.js API route
Hello! I'm running into an authentication issue when calling Convex mutations from Next.js API routes. I'm getting "User not authenticated" error when calling ctx.auth.getUserIdentity() inside a Convex mutation that's being called from a Next.js API route. However, other mutations that also use ctx.auth.getUserIdentity() work perfectly when called from client components that are wrapped in Clerk's <Authenticated> component.
Next.js API route
Convex Mutation
Could I get some help on this?
2 Replies
fetchMutation
(and fetchQuery/fetchAction/preloadQuery
) accept a third args object of Nextjs options, you can pass a token there to authenticate the function call.Thank you so much @erquhart! It's working now 😊 yay