adelin-b
adelin-b
CCConvex Community
Created by adelin-b on 3/15/2025 in #support-community
ContextHttpClient, setAuth, cannot get user from ctx
So im trying to call a query from the http client, and this query will need to be auth because we want to access ctx.getIdentity inside.
const convexHttpClient = new ConvexHttpClient(
process.env.NEXT_PUBLIC_CONVEX_URL!,

);

convexHttpClient.setAuth(config.authToken); // good token with template: "convex" that works when calling httpAction


const decks = await convexHttpClient.query(api.decks.list, {
organizationId: config.organizationId || null,
});
// ERROR inside the deck list query : const identity = await ctx.auth.getUserIdentity(); is NULL, expecting user

return decks;
const convexHttpClient = new ConvexHttpClient(
process.env.NEXT_PUBLIC_CONVEX_URL!,

);

convexHttpClient.setAuth(config.authToken); // good token with template: "convex" that works when calling httpAction


const decks = await convexHttpClient.query(api.decks.list, {
organizationId: config.organizationId || null,
});
// ERROR inside the deck list query : const identity = await ctx.auth.getUserIdentity(); is NULL, expecting user

return decks;
It seems that setAuth do nothing, how do I access ctx inside my deck.list query to have the user identity
2 replies
CCConvex Community
Created by adelin-b on 3/9/2025 in #support-community
Bug in httpAction, Authorization Bearer not working. Identity is null
Hello, im having the same trouble with auth through an http action On the documentation https://docs.convex.dev/auth/functions-auth#http-actions it says that if I put an Authorization token then ctx.auth.getUserIndentity should return the user, however this is broken. Seems like it get stripped because its not even visible in the preflight I'm using clerk as auth provider if that helps.
const token = useAuthToken();
useEffect(() => {
const fetchData = async () => {
const response = await fetch(`${CONVEX_SITE_URL}/api/chat`, {
method: "POST",
body: JSON.stringify({ messages: [] }),
headers: {
Authorization: `Bearer ${token}`,
},
});
console.log(response);
};
fetchData();
}, [token]);
const token = useAuthToken();
useEffect(() => {
const fetchData = async () => {
const response = await fetch(`${CONVEX_SITE_URL}/api/chat`, {
method: "POST",
body: JSON.stringify({ messages: [] }),
headers: {
Authorization: `Bearer ${token}`,
},
});
console.log(response);
};
fetchData();
}, [token]);
http.route({
path: "/api/chat",
method: "OPTIONS",
handler: httpAction(async (ctx, request) => {
console.log("ctx auth", await ctx.auth.getUserIdentity()); // NULL

// Make sure the necessary headers are present
// for this to be a valid pre-flight request
const headers = request.headers;
console.log("headers", JSON.stringify(headers, null, 2)); // Dont show the authorization header even
return headers.get("Origin") !== null &&
headers.get("Access-Control-Request-Method") !== null &&
headers.get("Access-Control-Request-Headers") !== null
? new Response(null, {
headers: new Headers({
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST",
"Access-Control-Allow-Headers": "Content-Type, Digest",
"Access-Control-Max-Age": "86400",
Vary: "origin",
}),
})
: new Response();
}),
});
http.route({
path: "/api/chat",
method: "OPTIONS",
handler: httpAction(async (ctx, request) => {
console.log("ctx auth", await ctx.auth.getUserIdentity()); // NULL

// Make sure the necessary headers are present
// for this to be a valid pre-flight request
const headers = request.headers;
console.log("headers", JSON.stringify(headers, null, 2)); // Dont show the authorization header even
return headers.get("Origin") !== null &&
headers.get("Access-Control-Request-Method") !== null &&
headers.get("Access-Control-Request-Headers") !== null
? new Response(null, {
headers: new Headers({
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST",
"Access-Control-Allow-Headers": "Content-Type, Digest",
"Access-Control-Max-Age": "86400",
Vary: "origin",
}),
})
: new Response();
}),
});
3 replies
CCConvex Community
Created by adelin-b on 8/6/2024 in #support-community
How to cascade delete an entity and all references to it in other entities
given a schema like this :
modules: defineTable({
name: v.string(),
documentIds: v.array(v.id("documents")),
})
documents: defineTable({
name: v.string(),
content: v.optional(v.string()),
})
modules: defineTable({
name: v.string(),
documentIds: v.array(v.id("documents")),
})
documents: defineTable({
name: v.string(),
content: v.optional(v.string()),
})
How do should I proceed to have the documentIds automatically removed from the modules when a document is deleted ? I could add a call to the db in the document:delete query so it update the associated modules but I wonder if there is something more robust like a cascading option somewhere like in postgres
6 replies
CCConvex Community
Created by adelin-b on 7/30/2024 in #support-community
How to auth in local mode
Hello, with the current outage and the fact i had to take the train recently. I found the need to run a version of convex in local so I can develop nicely without connection / when convex/clerk has issues. Any hints or pointers ?
2 replies
CCConvex Community
Created by adelin-b on 7/24/2024 in #support-community
How to get Clerk user current selected Organisation
Hello, I would like to be able to know which organisation the user belong to without having to pass it in the query. Two problem: - I added it to the clerk jwt, however in the getIndentity i do not have access to it. - If I do this, how can I invalidate data for the client-side that changed organization ?
8 replies