jeremienegie
jeremienegie
CCConvex Community
Created by jeremienegie on 9/10/2024 in #support-community
getAuthUserId with tanstack userId null
Hi @ballingt I wanted to ask if you had a look at the problem
16 replies
CCConvex Community
Created by jeremienegie on 9/10/2024 in #support-community
getAuthUserId with tanstack userId null
Okay thank you.
16 replies
CCConvex Community
Created by jeremienegie on 9/10/2024 in #support-community
getAuthUserId with tanstack userId null
// convex/channels.ts
export const getById = query({
args: {
id: v.id("channels"),
},
handler: async (ctx, args) => {
const userId = await getAuthUserId(ctx);

if (!userId) {
return null;
}

const channel = await ctx.db.get(args.id);

if (!channel) {
return null;
}

const member = await ctx.db
.query("members")
.withIndex("by_workspace_id_user_id", (q) =>
q.eq("workspaceId", channel.workspaceId).eq("userId", userId)
)
.unique();

if (!member) {
return null;
}

return channel;
},
});
// convex/channels.ts
export const getById = query({
args: {
id: v.id("channels"),
},
handler: async (ctx, args) => {
const userId = await getAuthUserId(ctx);

if (!userId) {
return null;
}

const channel = await ctx.db.get(args.id);

if (!channel) {
return null;
}

const member = await ctx.db
.query("members")
.withIndex("by_workspace_id_user_id", (q) =>
q.eq("workspaceId", channel.workspaceId).eq("userId", userId)
)
.unique();

if (!member) {
return null;
}

return channel;
},
});
// use-get-channel.ts
import { Id } from "../../../../convex/_generated/dataModel";
// import { useQuery } from "convex/react";
import { api } from "../../../../convex/_generated/api";
import { useQuery } from "@tanstack/react-query";
import { convexQuery } from "@convex-dev/react-query";

type UseGetChannelProps = {
id: Id<"channels">;
};

// I console.log userId and it prints the userId
// export const useGetChannel = ({ id }: UseGetChannelProps) => {
// const data = useQuery(api.channels.getById, { id });
// const isLoading = data === undefined;

// return { data, isLoading };
// };


// I console.log userId and it shows null
export const useGetChannel = ({ id }: UseGetChannelProps) => {
const query = useQuery({ ...convexQuery(api.channels.getById, { id }) });
return query;
};
// use-get-channel.ts
import { Id } from "../../../../convex/_generated/dataModel";
// import { useQuery } from "convex/react";
import { api } from "../../../../convex/_generated/api";
import { useQuery } from "@tanstack/react-query";
import { convexQuery } from "@convex-dev/react-query";

type UseGetChannelProps = {
id: Id<"channels">;
};

// I console.log userId and it prints the userId
// export const useGetChannel = ({ id }: UseGetChannelProps) => {
// const data = useQuery(api.channels.getById, { id });
// const isLoading = data === undefined;

// return { data, isLoading };
// };


// I console.log userId and it shows null
export const useGetChannel = ({ id }: UseGetChannelProps) => {
const query = useQuery({ ...convexQuery(api.channels.getById, { id }) });
return query;
};
I shared my layout.ts above I don't think I'm running two convex client but ey I'm just learning convex I don't understand why one working anf the other no my mutations with tanstack is running perfectly with the set up I have
16 replies
CCConvex Community
Created by jeremienegie on 9/10/2024 in #support-community
getAuthUserId with tanstack userId null
From the client so when I do this
export const useGetChannel = ({ id }: UseGetChannelProps) => {
const data = useQuery(api.channels.getById, { id });
const isLoading = data === undefined;

return { data, isLoading };
};
export const useGetChannel = ({ id }: UseGetChannelProps) => {
const data = useQuery(api.channels.getById, { id });
const isLoading = data === undefined;

return { data, isLoading };
};
UserId in getById is there but doing this
export const useGetChannel = ({ id }: UseGetChannelProps) => {
const query = useQuery({ ...convexQuery(api.channels.getById, { id }) });
return query;
};
export const useGetChannel = ({ id }: UseGetChannelProps) => {
const query = useQuery({ ...convexQuery(api.channels.getById, { id }) });
return query;
};
For some reason userId is null
16 replies
CCConvex Community
Created by jeremienegie on 9/10/2024 in #support-community
getAuthUserId with tanstack userId null
mutations are working fine it's just queries
16 replies
CCConvex Community
Created by jeremienegie on 9/10/2024 in #support-community
getAuthUserId with tanstack userId null
this in my layout.tsx
16 replies
CCConvex Community
Created by jeremienegie on 9/10/2024 in #support-community
getAuthUserId with tanstack userId null
<ConvexAuthNextjsServerProvider>
<html lang="en">
<body className={inter.className}>
<ConvexClientProvider>
<TanstackProvider>
<JotaiProvider>
<Toaster />
<Modals />
{children}
</JotaiProvider>
</TanstackProvider>
</ConvexClientProvider>
</body>
</html>
</ConvexAuthNextjsServerProvider>
<ConvexAuthNextjsServerProvider>
<html lang="en">
<body className={inter.className}>
<ConvexClientProvider>
<TanstackProvider>
<JotaiProvider>
<Toaster />
<Modals />
{children}
</JotaiProvider>
</TanstackProvider>
</ConvexClientProvider>
</body>
</html>
</ConvexAuthNextjsServerProvider>
16 replies