unsphere
unsphere
CCConvex Community
Created by unsphere on 10/9/2024 in #support-community
How to use Buffer in httpRouter?
Some npm packages I need rely on Buffer and I am already using "use node" for convexAuth ConvexCredentials that is working fine. But then I get the following error:
InvalidModules: Hit an error while pushing:
Loading the pushed modules encountered the following
error:
Failed to analyze http.js: Uncaught ReferenceError: Buffer is not defined
at node_modules/@ton/core/dist/boc/BitString.js (../../node_modules/@ton/core/dist/boc/BitString.js:167:53)
at __require2 (convex:/_deps/225NMHCD.js:16:50)
at node_modules/@ton/core/dist/boc/BitBuilder.js (../../node_modules/@ton/core/dist/boc/BitBuilder.js:16:0)
at __require2 (convex:/_deps/225NMHCD.js:16:50)
at node_modules/@ton/core/dist/boc/Builder.js (../../node_modules/@ton/core/dist/boc/Builder.js:11:15)
at __require2 (convex:/_deps/225NMHCD.js:16:50)
at node_modules/@ton/core/dist/address/contractAddress.js (../../node_modules/@ton/core/dist/address/contractAddress.js:11:6)
at __require2 (convex:/_deps/225NMHCD.js:16:50)
at node_modules/@ton/core/dist/index.js (../../node_modules/@ton/core/dist/index.js:33:22)
at __require2 (convex:/_deps/225NMHCD.js:16:50)
InvalidModules: Hit an error while pushing:
Loading the pushed modules encountered the following
error:
Failed to analyze http.js: Uncaught ReferenceError: Buffer is not defined
at node_modules/@ton/core/dist/boc/BitString.js (../../node_modules/@ton/core/dist/boc/BitString.js:167:53)
at __require2 (convex:/_deps/225NMHCD.js:16:50)
at node_modules/@ton/core/dist/boc/BitBuilder.js (../../node_modules/@ton/core/dist/boc/BitBuilder.js:16:0)
at __require2 (convex:/_deps/225NMHCD.js:16:50)
at node_modules/@ton/core/dist/boc/Builder.js (../../node_modules/@ton/core/dist/boc/Builder.js:11:15)
at __require2 (convex:/_deps/225NMHCD.js:16:50)
at node_modules/@ton/core/dist/address/contractAddress.js (../../node_modules/@ton/core/dist/address/contractAddress.js:11:6)
at __require2 (convex:/_deps/225NMHCD.js:16:50)
at node_modules/@ton/core/dist/index.js (../../node_modules/@ton/core/dist/index.js:33:22)
at __require2 (convex:/_deps/225NMHCD.js:16:50)
Using "use node" inside of the httpRouter file where the ConvexAuth http actions will be consumed is not allowed.
"use node" directive is not allowed for http.ts.
"use node" directive is not allowed for http.ts.
Any idea?
4 replies
CCConvex Community
Created by unsphere on 9/3/2024 in #support-community
How to obtain cookies in Convex Auth ConvexCredentials authorize?
Hi there, is it somehow possible to get the cookies inside ConvexCredentials authorize? I need to get them to verify the credentials. In NextAuth there is the req parameter in authorize. Your http actions have it as well.
export const { auth, signIn, signOut, store } = convexAuth({
providers: [
ConvexCredentials({
id: "siwe",
authorize: async (
credentials: {
message?: string;
signature?: `0x${string}`;
},
ctx,
) => {
try {
const { message, signature } = credentials;

if (!message || !signature) {
return null;
}

const parsed = parseSiweMessage(message);

if (!parsed.nonce || !parsed.address || !parsed.chainId) {
return null;
}

const chain = Object.values(chains).find(
(chain) => chain.id === parsed.chainId,
);

if (!chain) {
return null;
}

/* NEED COOKIES HERE
const session = await getIronSession<{ nonce: string }>(cookies(), sessionConfig);

if (parsed.nonce !== session.nonce) {
return null
}
*/

const publicClient = createPublicClient({
chain,
transport: http(),
});

const verified = await publicClient.verifySiweMessage({
message,
signature,
//nonce: session.nonce,
scheme: process.env.NODE_ENV === "development" ? "http" : "https",
domain: DOMAIN,
time: new Date(),
});

if (!verified) {
return null;
}

const userId = await ctx.runMutation(internal.user.store, {
wallet: parsed.address,
});

return {
userId,
};
} catch (error) {
console.error(error);
return null;
}
},
}),
],
});
export const { auth, signIn, signOut, store } = convexAuth({
providers: [
ConvexCredentials({
id: "siwe",
authorize: async (
credentials: {
message?: string;
signature?: `0x${string}`;
},
ctx,
) => {
try {
const { message, signature } = credentials;

if (!message || !signature) {
return null;
}

const parsed = parseSiweMessage(message);

if (!parsed.nonce || !parsed.address || !parsed.chainId) {
return null;
}

const chain = Object.values(chains).find(
(chain) => chain.id === parsed.chainId,
);

if (!chain) {
return null;
}

/* NEED COOKIES HERE
const session = await getIronSession<{ nonce: string }>(cookies(), sessionConfig);

if (parsed.nonce !== session.nonce) {
return null
}
*/

const publicClient = createPublicClient({
chain,
transport: http(),
});

const verified = await publicClient.verifySiweMessage({
message,
signature,
//nonce: session.nonce,
scheme: process.env.NODE_ENV === "development" ? "http" : "https",
domain: DOMAIN,
time: new Date(),
});

if (!verified) {
return null;
}

const userId = await ctx.runMutation(internal.user.store, {
wallet: parsed.address,
});

return {
userId,
};
} catch (error) {
console.error(error);
return null;
}
},
}),
],
});
3 replies
CCConvex Community
Created by unsphere on 12/5/2023 in #support-community
Using solc inside actions
I want to use the solc lib inside functions. The lib has dependencies to fs or path. I already put "use node" on top with only actions inside and still get the following error. I will not use any function from solc that uses fs and others. ✘ [ERROR] Could not resolve "fs" node_modules/solc/soljson.js:115:21: 115 │ fs = require("fs"); ╵ ~~~~ The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2 replies
CCConvex Community
Created by unsphere on 11/5/2023 in #support-community
Multiple queries suggestion
I have a queue list and thinking about the best query design, performance and resources wise. The queue displays tickets as follows: 1. active (one) 2. prioritized (multiple) creation time asc 3. in queue (multiple) creation time asc 4. processed (multiple) processed time desc I am also thinking about pagination for prioritized, in queue and processed ones so that the user sees the active one + 20 after that in the order specified on top and on scroll i load 20 more either prioritized ones if not end reached or in queue ones if not end reached and so on. Should I create 4 queries with indexes including pagination leveraging skip feature if end is reached of the previous query or should I put all in one like:
export const list = query({
args: { receiverId: v.id('users') },
handler: async (ctx, { receiverId }) => {
const [active, prioritized, queue, processed] = await Promise.all([
ctx.db
.query('tickets')
.withIndex('byReceiverIdAndIsActive', (q) =>
q.eq('receiverId', receiverId).eq('isActive', true)
)
.first(),
ctx.db
.query('tickets')
.withIndex('byReceiverIdAndIsActiveAndIsPrioritizedAndIsProcessed', (q) =>
q
.eq('receiverId', receiverId)
.eq('isActive', false)
.eq('isPrioritized', true)
.eq('isProcessed', false)
)
.order('asc')
.collect(),
ctx.db
.query('tickets')
.withIndex('byReceiverIdAndIsActiveAndIsPrioritizedAndIsProcessed', (q) =>
q
.eq('receiverId', receiverId)
.eq('isActive', false)
.eq('isPrioritized', false)
.eq('isProcessed', false)
)
.order('asc')
.collect(),
ctx.db
.query('tickets')
.withIndex('byReceiverIdAndIsProcessed', (q) =>
q.eq('receiverId', receiverId).eq('isProcessed', true)
)
.order('desc')
.collect(),
]);
...
export const list = query({
args: { receiverId: v.id('users') },
handler: async (ctx, { receiverId }) => {
const [active, prioritized, queue, processed] = await Promise.all([
ctx.db
.query('tickets')
.withIndex('byReceiverIdAndIsActive', (q) =>
q.eq('receiverId', receiverId).eq('isActive', true)
)
.first(),
ctx.db
.query('tickets')
.withIndex('byReceiverIdAndIsActiveAndIsPrioritizedAndIsProcessed', (q) =>
q
.eq('receiverId', receiverId)
.eq('isActive', false)
.eq('isPrioritized', true)
.eq('isProcessed', false)
)
.order('asc')
.collect(),
ctx.db
.query('tickets')
.withIndex('byReceiverIdAndIsActiveAndIsPrioritizedAndIsProcessed', (q) =>
q
.eq('receiverId', receiverId)
.eq('isActive', false)
.eq('isPrioritized', false)
.eq('isProcessed', false)
)
.order('asc')
.collect(),
ctx.db
.query('tickets')
.withIndex('byReceiverIdAndIsProcessed', (q) =>
q.eq('receiverId', receiverId).eq('isProcessed', true)
)
.order('desc')
.collect(),
]);
...
15 replies