Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SessionMiddleware not available on Vercel #13

Open
edmbn opened this issue Nov 14, 2021 · 11 comments
Open

SessionMiddleware not available on Vercel #13

edmbn opened this issue Nov 14, 2021 · 11 comments

Comments

@edmbn
Copy link

edmbn commented Nov 14, 2021

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

@edmbn edmbn changed the title SessionMiddleware to available on Vercel SessionMiddleware not available on Vercel Nov 14, 2021
@beerose
Copy link
Contributor

beerose commented Nov 15, 2021

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

@edmbn
Copy link
Author

edmbn commented Nov 15, 2021

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
Copy link
Contributor

beerose commented Nov 15, 2021

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
Copy link
Author

edmbn commented Nov 15, 2021

With next-translate I can't reproduce it locally

@edmbn
Copy link
Author

edmbn commented Nov 15, 2021

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

@armandabric
Copy link

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
Copy link

matthieuh commented Mar 11, 2022

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

@matthieuh
Copy link

Sorry, but was is the status of this issue? This is not clear to me since this one is closed: #385

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

@dillondotzip dillondotzip transferred this issue from blitz-js/blitz Jul 7, 2022
@dawangraoming
Copy link

blitz-js/blitz#3536

same problem 🥲

Is it have any solution?

@ericmil87
Copy link

Running into this problem today. Any fixes?

@dawangraoming
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants