Ammar
Ammar
Explore posts from servers
TtRPC
Created by Ammar on 2/25/2025 in #❓-help
How to get cursor in new Tanstack Query integration?
How can I access the cursor (or pageParam) in the new infiniteQueryOptions function? The current procedure input takes a cursor but I'm getting and error saying cursor is not passed to infiniteQueryOptions, and I can't pass it manually as it is calculated using getNextPageParam.
2 replies
TTCTheo's Typesafe Cult
Created by Ammar on 5/28/2023 in #questions
tRPC API calls log user out automatically
Whenever I call a tRPC API route (protected or public), I immediately get logged out. I have no idea what I'm doing wrong. Here's my code:
// [...nextauth].ts
import NextAuth from "next-auth";
import { NextAuthOptions } from "next-auth";
import GoogleProvider from "next-auth/providers/google";

export const authOptions: NextAuthOptions = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
}),
],
secret: process.env.NEXTAUTH_SECRET!,
};

export default NextAuth(authOptions);
// [...nextauth].ts
import NextAuth from "next-auth";
import { NextAuthOptions } from "next-auth";
import GoogleProvider from "next-auth/providers/google";

export const authOptions: NextAuthOptions = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
}),
],
secret: process.env.NEXTAUTH_SECRET!,
};

export default NextAuth(authOptions);
// post.ts (in server/api/routers)
import { z } from "zod";
import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";

export const postRouter = createTRPCRouter({
create: protectedProcedure
.input(z.object({ content: z.string() }))
.mutation(async ({ input: { content }, ctx }) => {
const post = await ctx.prisma.post.create({
data: {
content,
userId: ctx.session.user.id,
},
});

return post;
}),
});
// post.ts (in server/api/routers)
import { z } from "zod";
import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";

export const postRouter = createTRPCRouter({
create: protectedProcedure
.input(z.object({ content: z.string() }))
.mutation(async ({ input: { content }, ctx }) => {
const post = await ctx.prisma.post.create({
data: {
content,
userId: ctx.session.user.id,
},
});

return post;
}),
});
// NewPost.tsx (in components)
const createPost = api.post.create.useMutation({
onSuccess: (newPost) => {
setInputValue("");
},
});

function handleSubmit(e: FormEvent) {
e.preventDefault();
createPost.mutate({ content: inputValue });
}
// NewPost.tsx (in components)
const createPost = api.post.create.useMutation({
onSuccess: (newPost) => {
setInputValue("");
},
});

function handleSubmit(e: FormEvent) {
e.preventDefault();
createPost.mutate({ content: inputValue });
}
10 replies