RoninR
Convex Community16mo ago
7 replies
Ronin

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.
Screenshot_2024-09-28_104656.png
Screenshot_2024-09-20_002515.png
Was this page helpful?