shadow_ayaS
Convex Community3y ago
14 replies
shadow_aya

Query typing malfunction

I've got an issue where the destroy method from my session store doesn't work. Upon further inspection, I found out that one of my Convex functions returns random values (table entries with seemingly valid data that don't exist in reality).
I cleared my siteSessions table, and still got results for non-existent documents. Even when there are results, _id is in mismatch. My other tables are small enough as of now that I even checked elsewhere, and the logged _id was nowhere to be found.

I'm not sure why this is happening, all my code is attached. I hope I made a stupid mistake or overlooked something rather than there being an underlying issue. Note that I deleted some documents by hand, but I don't think that should have any effect.

session.Store#destroy method
class ConvexSiteSessionStore extends session.Store {

    // ...

    destroy(sid: string, callback?: ((err?: any) => void) | undefined) {

        convex.query(api.siteSessions.findBySid, {sid: sid}).then((session) => {

            console.log(session); // logging here

            if (!session) callback();
            else convex.mutation(api.siteSessions.remove, {id: session._id}).then(() => {
                callback();
            }).catch((err) => {
                callback(err);
            });
        }).catch((err) => {
            callback(err);
        });
        
    }
}

siteSessions#findBySid Convex function
export const findBySid = query({
    args: {
        sid: v.string(),
    },
    async handler(ctx, args) {
        return await ctx.db
            .query("siteSessions")
            .withIndex("by_sid") // also tried without the index
            .filter((q) =>
                q.eq(q.field("sid"), args.sid)
            )
            .first();
    },
});

siteSessions table schema
    siteSessions: defineTable({
        sid: v.string(),
        data: v.string(),
        expires: v.number(),
    })
        .index("by_sid", ["sid"])
Was this page helpful?