Comments (9)
I ran into the same problem when i switched over my project to use yarn...I removed the now-logs dependency, which includes the xmlhttprequest-ssl package. You need that one...the ssl version: https://www.npmjs.com/package/xmlhttprequest-ssl
not the older xmlhttprequest package.
from nextjs-starter.
My app run on heroku. the strange thing is that when a user is logging and have a token in the local storage, the app crashes every some days and the error in the console is "XMLHttpRequest is not defined". it's possible to replace the XMLHttpRequest with fetch or axios?
from nextjs-starter.
I see now that when i remove the connect.sid cookie the app back to normal. any ideas?
from nextjs-starter.
Hmm I'm not sure what's going on here, I'll see if I can replicate on Heroku. It shouldn't be calling XMLHttpRequest on the server ever. Maybe something Heroku specific is going on.
The reason it uses XMLHttpRequest rather than fetch is interesting, it's actually to do with having HTTP Only cookies (that can't be read in JavaScript) while still supporting universal rendering.
It does this to provide a "best practice" example but actually it complicates authentication significantly,
and I'm considering if it's worth the hassle of supporting.
I'll investigate and get back to you.
from nextjs-starter.
Hi @kamish24six - tried deploying to Heroku, found an issue and fixed it - it's now working on Heroku.
The issue seemed to be that Heroku didn't know to run "next build" before running "next start" (required on production for Next.js apps).
I added "postinstall": "next build"
to the package.json file under scripts
.
The scripts section in package.json
now looks like this:
"scripts": {
"test": "xo",
"dev": "NODE_ENV=development PORT=3000 node index.js",
"build": "next build",
"start": "node index.js",
"postinstall": "next build"
},
I've confirmed I was able to deploy directly from GitHub to Heroku and log in so it should work for you now.
Note you will need to configure authentication via env vars. It's probably easiest to configure email authentication first, just to check it's all working. You don't need to configure a user database just for testing, but if you don't the database will just be erased every time you restart the service.
from nextjs-starter.
Thanks. In the past I succeeded to upload the project to heroku, and it works.Oftentimes it can suddenly stop working and and an XMLHttpRequest error appears. When ן delete the connect.sid cookie is starts working again.
from nextjs-starter.
Interesting! Thanks for the added detail.
I'm going to re-open this and see if I can replicate the problem.
from nextjs-starter.
Thanks to your bug report I think I have a fix for this rolled out now!
I did a review of all calls to XMLHttpRequest in the project (they are all in components/session.js) and there was one place where XMLHttpRequest could accidentally be called while running on the server (which it should never be).
It could happen when the client had an existing session, but it had expired on the server and then the page was reloaded on the client (e.g. with refresh, or by visiting the site again after a period of being idle). This explains why it didn't happen right away.
I do want to refactor this code, and I did get a pull request for that, but there were some issue with the PR and I had to revert the change unfortunately. Most of the complexity is caused by the code supporting HTTP Only cookies.
I will see what the browser support for fetch with credentials: 'same-origin' is like to see if it works with HTTP Only cookies in browsers now, and if so trying and merge that pull request back in - the code isn't that complex, but fetch is a terser and easier to read and debug.
Thanks for the bug report!
I'd appreciate any feedback if you still see this issue with version 4.2.7
from nextjs-starter.
Addendum: I've actually just gone ahead and refactored the Session class to use fetch now.
from nextjs-starter.
Related Issues (20)
- Upgrade the deployment settings to now v2 HOT 5
- Authentication.md HOT 1
- Adding CORS HOT 2
- Other CSS Framework
- Can i get res in next-auth.functions ?
- What do i need to pull data from a collection?
- TypeError: Cannot read property 'passport' of undefined on production build HOT 1
- Several dependencies need to be updated HOT 1
- Nodemailer needs to be updated HOT 1
- Update to next.js 9? HOT 3
- build:server & export:server commands are not working
- FullCalendar in Nextjs
- Cloning and installing packages is failing because package-lock.json is present
- npm install fails HOT 2
- Memory leak in app created from this boilerplate
- Sign in doesn't work - takes to page not found '_error' does not exist.
- Deployment to Now v2 HOT 2
- 📢 Plans for the future HOT 2
- npm install error - remove package-lock.json before running npm i HOT 1
- 🚨 This project is now archived
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nextjs-starter.