TheNinjrKillrT
Convex Community2y ago
5 replies
TheNinjrKillr

Convex+Clerk lack of Auth within preloadQuery

I'm getting a strange error when using
preloadQuery
, where there is no authentication.

Use of preloadQuery:

export default async function CampaignsPage() {
    const { userId } = auth();

    if (!userId) return redirect("/");

    const preloadedCampaigns = await preloadQuery(api.db.players.getCampaigns);

    return (
        <CampaignPageContent
            userID={userId}
            preloadedCampaigns={preloadedCampaigns}
        />
    );
}


api.db.players.getCampaigns
:
export const getCampaigns = query({
    args: {},
    handler: async (ctx, args) => {
        const identity = await ctx.auth.getUserIdentity();
        if (identity === null) {
            throw new Error("Unauthenticated call to query!");
        }
        // Do stuff here

This was working perfectly when I was just using
useQuery
within my Client-rendered
<CampaignPageContent>
component.

Any thoughts / advice?
image.png
Was this page helpful?