tRPCttRPC
Powered by
Eka YudaE
tRPC•13mo ago•
1 reply
Eka Yuda

Next-auth session error

I have already setup tRPC v11.0.0-rc.666 with next auth v5.0.0-beta.25 but when i use the
await auth()
await auth()
in tRPC context got error
Error [TRPCClientError]: 
Error [TRPCClientError]: 
headers
 was called outside a request scope.
 was called outside a request scope.



import { PrismaClient } from "@prisma/client";
import * as trpcNext from "@trpc/server/adapters/next";

import { auth } from "@/libs/auth-js";

export async function createContext(opts?: trpcNext.CreateNextContextOptions) {
  const prisma = new PrismaClient();
  const session = await auth();

  return { prisma, req: opts?.req, res: opts?.res, session };
}

export type Context = Awaited<ReturnType<typeof createContext>>;
import { PrismaClient } from "@prisma/client";
import * as trpcNext from "@trpc/server/adapters/next";

import { auth } from "@/libs/auth-js";

export async function createContext(opts?: trpcNext.CreateNextContextOptions) {
  const prisma = new PrismaClient();
  const session = await auth();

  return { prisma, req: opts?.req, res: opts?.res, session };
}

export type Context = Awaited<ReturnType<typeof createContext>>;
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Next-auth session not being fetched in tRPC context
MinhazMMinhaz / ❓-help
3y ago
error: NEXT_REDIRECT
XavierBreadXXavierBread / ❓-help
2y ago