trevor
trevor
CCConvex Community
Created by trevor on 12/28/2023 in #support-community
How to interact with Convex from an external Lambda / Serverless?
@ballingt now that I played around with this some more, I was able to get it working without necessarily passing the token from the frontend to the backend.
const convex = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL ?? "");
const clerkSessionCookie = cookies().get("__session")?.value ?? "";
const sessionJwt = decodeJwt(clerkSessionCookie);
const sessionID = sessionJwt.payload.sid;
const token = await clerkClient.sessions.getToken(sessionID, "convex");
convex.setAuth(token);
await convex.query(api.users.currentUser);
const convex = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL ?? "");
const clerkSessionCookie = cookies().get("__session")?.value ?? "";
const sessionJwt = decodeJwt(clerkSessionCookie);
const sessionID = sessionJwt.payload.sid;
const token = await clerkClient.sessions.getToken(sessionID, "convex");
convex.setAuth(token);
await convex.query(api.users.currentUser);
Does feel a bit roundabout, so just want to make sure this is what you'd recommend as well. Cheers and also thank you again for the quick and insightful reply, I really did appreciate that.
6 replies
CCConvex Community
Created by trevor on 12/28/2023 in #support-community
How to interact with Convex from an external Lambda / Serverless?
Wow. Your suggestion worked immediately. Major kudos and appreciation to you. It was the same getToken function you found in the Clerk docs as you thought.
6 replies