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;
}
},
}),
],
});