So i have trpc set up with next.js and im trying to ssr where i fetch user before page load using trpc.useQuery hook, but i don't get the cookie with JWT token in trpc context
i have this code in [username].tsx page:
const UserPage: NextPage = () => {
const router = useRouter();
const username = router.query.username as string;
const user = trpc.useQuery([
"user.by-username",
{
username,
},
]);
return <Text>{user?.data?.id}</Text>;
};
export default UserPage;
and this code in trpc context, where i can't console.log the cookies:
export const createContext = (opts?: trpcNext.CreateNextContextOptions) => {
const req = opts?.req;
const res = opts?.res;
console.log(req?.cookies) // i don't get cookies here
const user = jwt.verify(req?.cookies.token as string, process.env.JWT_SECRET as string) as User
return {
req,
res,
prisma,
user
};
};
type Context = trpc.inferAsyncReturnType<typeof createContext>;
export const createRouter = () => trpc.router<Context>();