Ronin
Ronin•3mo ago

Convex api not working and causing problem in user validations from the convex tables

The function query below is not working, I might be using it incorrectly but would be a big help to get some advice on this // to return all spaces present in the current project export const get = query({ args: {}, handler: async (ctx) => { const identity = await ctx.auth.getUserIdentity();
if (!identity) { throw new Error("Not authenticated"); } const userId = identity.subject; return await ctx.db .query("spaces") .filter(q => q.eq(q.field("userId"), userId)) .collect(); } }); and the way I am calling it to check whether the user is exists or not import { useQuery } from "convex/react"; import { api } from "@convex/_generated/api"; export const useGetSpaces = () => { const data = useQuery(api.spaces.get); const isLoading = data === undefined; return {data, isLoading} } the {api} API i import from _generated/api from convex is causing error, would like to get some advice on how to resolve this issue and I would like to point out that we are using clerk for authentication.
No description
No description
4 Replies
Convex Bot
Convex Bot•3mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
jamalsoueidan
jamalsoueidan•3mo ago
it seems like api.spaces.get have some args missing in your frontend const data = useQuery(api.spaces.get, {}) Can you share your whole code?
sshader
sshader•3mo ago
https://docs.convex.dev/auth/debug#ctxauthgetuseridentity-returns-null-in-a-query might be relevant for that first error. That second looks like you're calling a function that expects arguments { tokenIdentifier: "some string" } without providing the argument (but generally you don't want to provide something like tokenIdentifier or userId in arguments set by the client, and instead want to use auth, since the client can send whatever values it wants)
Debugging Authentication | Convex Developer Hub
You have followed one of our authentication guides but something is not working.
Ronin
RoninOP•3mo ago
Okay thanks, that was very helpful Yeah I might have some args missing in my frontend but now that @sshader gave some hints to solve the issue I'll start with that approach, but thanks for helping 🙂 Hey @sshader, I recently deployed our website preview on Vercel, and while users in India are able to interact with the site without any issues, my colleague in the United States has been experiencing an authentication error. I would appreciate your assistance in resolving this issue, as it seems to be location-specific. Please let me know if you require any further details to help diagnose the problem.

Did you find this page helpful?