blitz-js / blitz-js/legacy-framework
SessionMiddleware not available on Vercel
- Dominant language
- JavaScript
- Stars
- 3
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
### 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
.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_
Contributor guide
Research direction
Start with blitz.config.ts and the login.js stack trace, then reproduce session creation on a Vercel production deployment with next-translate enabled. Compare that behavior with the same configuration without next-translate and trace why SessionMiddleware leaves the authentication path unable to access $create. Done means login and session creation work on Vercel with the shown configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nextjs, typescript
- Domain
- api, authentication, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100