blitz-js / legacy-framework

MIT License
3 stars 2 forks source link

SessionMiddleware not available on Vercel #13

Open edmbn opened 2 years ago

edmbn commented 2 years ago

What is the problem?

Using Vercel on production, on latest version of Blitz (0.42.4), I get an authentication error: "Sorry, we had an unexpected error. Please try again. - TypeError: Cannot read property '$create' of undefined".

Paste all your error logs here:

ERROR login() 
 TypeError  Cannot read property '$create' of undefined
error stack:
• login.js:68 <anonymous>
.next/serverless/pages/api/rpc/login.js:68:21

Paste all relevant code snippets here:

This is my blitz.config.ts (without next-translate worked fine):

import { BlitzConfig, sessionMiddleware, simpleRolesIsAuthorized } from "blitz"
const nextTranslate = require("next-translate")

const config: BlitzConfig = {
  i18n: {
    locales: ["es", "en"],
    defaultLocale: "en",
  },
  middleware: [
    sessionMiddleware({
      cookiePrefix: "hirin_app",
      sessionExpiryMinutes: MAX_AGE_IN_MINUTES,
      isAuthorized: simpleRolesIsAuthorized,
      publicDataKeysToSyncAcrossSessions: ["role", "profileId"],
    }),
  ],
}

module.exports = nextTranslate(config)

What are detailed steps to reproduce this?

  1. Login and create a session when useTranslate is setup on blitz.config.ts while on Vercel production

Run blitz -v and paste the output here:

blitz: 0.42.4 (local)

  Package manager: yarn
  System:
    OS: macOS 12.0.1
    CPU: (8) arm64 Apple M1
    Memory: 71.84 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.0.1 - /var/folders/jk/757vpg1x69d1m6gpjdb1llgc0000gn/T/yarn--1636926036079-0.27845109624973885/node
    Yarn: 1.22.10 - /var/folders/jk/757vpg1x69d1m6gpjdb1llgc0000gn/T/yarn--1636926036079-0.27845109624973885/yarn
    npm: 8.1.0 - /opt/homebrew/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: 3.4.2 => 3.4.2
    blitz: 0.42.4 => 0.42.4
    prisma: 3.4.2 => 3.4.2
    react: alpha => 18.0.0-alpha-a44a7a2a3-20211111
    react-dom: alpha => 18.0.0-alpha-a44a7a2a3-20211111
    typescript: ~4.3 => 4.3.5

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

No response

beerose commented 2 years ago

Was it working with next-translate with previous Blitz releases?

edmbn commented 2 years ago

I didn't try since I was using next-rosetta. Once I added the blitz.config.ts change with next-translate it started showing this error on production.

beerose commented 2 years ago

I think there's a bug related to wrapping the config — I noticed the same issue locally with a different library. In your case, does it also happen locally?

edmbn commented 2 years ago

With next-translate I can't reproduce it locally

edmbn commented 2 years ago

I can confirm it's only happening on Vercel in my case. On Render it is working fine.

armandabric commented 2 years ago

I confirm I have the same issue on Vercel, but not on render (I just give it a try)

Linux 5.13 | linux-x64 | Node: v14.18.3

blitz: 0.45.3 (global)
blitz: 0.45.3 (local)

  Package manager: yarn 
  System:
    OS: Linux 5.13 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
    Memory: 169.30 MB / 15.33 GB
    Shell: 3.3.1 - /usr/bin/fish
  Binaries:
    Node: 14.18.3 - ~/.nvm/versions/node/v14.18.3/bin/node
    Yarn: 3.1.1 - /usr/bin/yarn
    npm: 6.14.16 - /usr/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: 3.9.2 => 3.9.2 
    blitz: 0.45.3 => 0.45.3 
    prisma: 3.9.2 => 3.9.2 
    react: 18.0.0-beta-149b420f6-20211119 => 18.0.0-beta-149b420f6-20211119 
    react-dom: 18.0.0-alpha-5ca4b0433-20211020 => 18.0.0-alpha-5ca4b0433-20211020 
    typescript: ~4.5.5 => 4.5.5 

I'm getting this after upgrading from 0.39.0 to 0.45.3.

matthieuh commented 2 years ago

I'm also confirming issue is still happening with version 0.45.3. Is there any workaround?

matthieuh commented 2 years ago

Sorry, but was is the status of this issue? This is not clear to me since this one is closed: https://github.com/blitz-js/legacy-framework/issues/385

Is there anything I could do to help on this topic?

dawangraoming commented 2 years ago

https://github.com/blitz-js/blitz/issues/3536

same problem 🥲

Is it have any solution?

ericmil87 commented 2 years ago

Running into this problem today. Any fixes?

dawangraoming commented 2 years ago

@ericmil87 no way if u use 0.x version, blitz team they dont wanna fix this in 0.x version

Have to use 2.x if u still wanna use blitz on vercel.