blitz-js / blitz

⚡️ The Missing Fullstack Toolkit for Next.js
https://Blitzjs.com
MIT License
13.68k stars 798 forks source link

Crash running getSession in prod #3791

Closed tmcw closed 1 year ago

tmcw commented 2 years ago

What is the problem?

Getting the following error trying to authenticate an API endpoint.

Paste all your error logs here:

Aug 24 10:30:38 AM  TypeError: Cannot read properties of undefined (reading 'getSession')
Aug 24 10:30:38 AM      at getSessionKernel (/opt/render/project/src/node_modules/@blitzjs/auth/dist/index-server.cjs:423:57)
Aug 24 10:30:38 AM      at getSession (/opt/render/project/src/node_modules/@blitzjs/auth/dist/index-server.cjs:142:29)
Aug 24 10:30:38 AM      at replicachePull (/opt/render/project/src/.next/server/chunks/495.js:271:84)
Aug 24 10:30:38 AM      at /opt/render/project/src/node_modules/@sentry/nextjs/cjs/utils/withSentry.js:78:35
Aug 24 10:30:38 AM      at bound (node:domain:421:15)
Aug 24 10:30:38 AM      at runBound (node:domain:432:12)
Aug 24 10:30:38 AM      at /opt/render/project/src/node_modules/@sentry/nextjs/cjs/utils/withSentry.js:133:12
Aug 24 10:30:38 AM      at Object.apiResolver (/opt/render/project/src/node_modules/next/dist/server/api-utils/node.js:179:15)
Aug 24 10:30:38 AM      at processTicksAndRejections (node:internal/process/task_queues:96:5)
Aug 24 10:30:38 AM      at async NextNodeServer.runApi (/opt/render/project/src/node_modules/next/dist/server/next-server.js:381:9)

Paste all relevant code snippets here:

async function replicachePull(req: NextApiRequest, res: NextApiResponse) {
  const session: SessionContext = await getSession(req, res); 
  session.$authorize();

What are detailed steps to reproduce this?

  1. Run the above code.

Run blitz -v and paste the output here:

Blitz version: 2.0.0-beta.3 (local)
macOS Monterey | darwin-arm64 | Node: v16.16.0

 Package manager: npm

  System:
    OS: macOS 12.5.1
    CPU: (8) arm64 Apple M2
    Memory: 362.83 MB / 24.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.16.0 - ~/.volta/tools/image/node/16.16.0/bin/node
    Yarn: 1.22.19 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn
    npm: 8.11.0 - ~/.volta/tools/image/node/16.16.0/bin/npm
  npmPackages:
    @blitzjs/auth: 2.0.0-beta.3 => 2.0.0-beta.3
    @blitzjs/next: 2.0.0-beta.3 => 2.0.0-beta.3
    @blitzjs/rpc: 2.0.0-beta.3 => 2.0.0-beta.3
    @prisma/client: ^4 => 4.2.1
    blitz: 2.0.0-beta.3 => 2.0.0-beta.3
    next: 12.2.0 => 12.2.0
    prisma: ^4 => 4.2.1
    react: ^18.0.0 => 18.2.0
    react-dom: ^18.0.0 => 18.2.0
    typescript: ~4.6 => 4.6.4

Please include below any other applicable logs and screenshots that show your problem:

No response

flybayer commented 2 years ago

@tmcw did you get this resolved? If so, how?

Rasikh-DMio commented 2 years ago

Having the exact same issue, for now I've disabled authenticating at endpoint(s)