Codex
Codex
Explore posts from servers
TtRPC
Created by Codex on 4/9/2024 in #❓-help
Context is not being passed correctly
Finally this is what is creating the session.
const createInnerTRPCContext = (opts: CreateContextOptions) => {
return {
session: opts.session,
prisma,
};
};

export const createTRPCContext = async (opts: CreateNextContextOptions) => {
const { req, res } = opts;
// Get the session from the server using the getServerSession wrapper function
const session = await getServerAuthSession({ req, res });
return createInnerTRPCContext({
session,
});
};
const createInnerTRPCContext = (opts: CreateContextOptions) => {
return {
session: opts.session,
prisma,
};
};

export const createTRPCContext = async (opts: CreateNextContextOptions) => {
const { req, res } = opts;
// Get the session from the server using the getServerSession wrapper function
const session = await getServerAuthSession({ req, res });
return createInnerTRPCContext({
session,
});
};
What is happening is that when the front end calls the session I properly get the role inside session.user.role. Moving from the front end to the actual API calls, the first time it creates the session in the middleware it is going through my session callback, and the session when logged DOES come with role and userId, However once it is returned it somehow loses those two values, and the context is set without those two. Any help is much appreciated thanks in advance. Setup: T3: Nextauth, Nextjs pages router, trpc, typescript and prisma. Node version: 18.18.1
3 replies