Closed ivanjeremic closed 4 years ago
Hi @ivanjeremic , is because in the repo there is no way to get the env vars right now, please do this:
npm install dotenv
Then in the file useMiddleware.js put:
import 'dotenv/config'; // This new line
import useDatabase from './useDatabase';
import useSession from './useSession';
import useAuthentication from './useAuthentication';
const middleware = handler =>
useDatabase(useSession(useAuthentication(handler)));
export default middleware;
and create a .env file in the root like: (Check the file starts with a dot --> .env)
MONGODB_URI="mongodb+srv://user:pass@testing-j4duk.mongodb.net/dbname?retryWrites=true&w=majority"
Also in the .env file you can put the Cloudinary path if you want to try that part too.
I hope it helps you
@julianux In the GitHub repo there was no dotenv
thats why I thought it is not needed. I have now followed the steps you told me and now the console trows this error.
(node:30196) UnhandledPromiseRejectionWarning: MongoError: not authorized on admin to execute command { createIndexes: "sessions", indexes: [[{name expires_1} {key [{expires 1}]} {expireAfterSeconds 0}]], writeConcern: { w: "majority" }, lsid: { id: {4 [156 192 7 101 240 33 65 202 157 135 193 15 223 161 150 61]} }, $clusterTime: { clusterTime: 6745668904883847169, signature: { hash: [171 121 241 5 43 171 222 78 87 184 251 130 146 173 164 149 95 161 175 75], keyId: 6742367827379879936.000000 } }, $db: "admin" }
EDIT The console error above I fixed by following this discussion https://stackoverflow.com/questions/54986716/node-js-mongoerror-not-authorized-on-admin-to-execute-command
Now the console error is fixed but same MongoStore error comming up like from the beginning.
Error: Connection strategy not found
at new MongoStore (D:\Development\Apps\mausys-web\node_modules\connect-mongo\src\index.js:129:15)
at useSession (D:\Development\Apps\mausys-web.next\server\static\development\pages\api\users.js:201:10)
at middleware (D:\Development\Apps\mausys-web.next\server\static\development\pages\api\users.js:177:151)
at Module../pages/api/users.js (D:\Development\Apps\mausys-web.next\server\static\development\pages\api\users.js:284:138)
at webpack_require (D:\Development\Apps\mausys-web.next\server\static\development\pages\api\users.js:23:31)
at Object.7 (D:\Development\Apps\mausys-web.next\server\static\development\pages\api\users.js:295:18)
at webpack_require (D:\Development\Apps\mausys-web.next\server\static\development\pages\api\users.js:23:31)
at D:\Development\Apps\mausys-web.next\server\static\development\pages\api\users.js:91:18
at Object.
@ivanjeremic Sorry for the lack of information, I just update README with the link to my article on the issue.
Where, which platform do you deploy your code? There might be an option to config environmental variable there. (After all, .env
is only used for development)
@ivanjeremic I also read the SO solution. It does not seem to be the case, I use mongodb+srv://
variation in connect-mongo
, and it works just fine. Perhaps, check your Atlas user setting? (Did you allow the user to READ+WRITE?)
Yes checked that as well everything fine, but still not working. I deploy on ZEIT maybe I need to set the secrets on the now platform because I use the newest version of Nextjs. https://zeit.co/blog/environment-variables-secrets
By the way any reason you go with session and not jsonwebtoken?
@ivanjeremic http://cryto.net/~joepie91/blog/2016/06/13/stop-using-jwt-for-sessions/ This article does a good job explaining the reasons. JWT is not bad. The way people misunderstanding and misusing it is bad. I saw a lot of JWT articles and most of them incorrectly use JWT.
@ivanjeremic please let me know if the problem is not resolved.
Hey @ivanjeremic, would love to have an update. Tell me if I can help in any way!
Hey @ivanjeremic, would love to have an update. Tell me if I can help in any way!
I will upload later today my repo that shows how I habe it and reproduces the error.
Closing: Already resolved a long time ago with doc update.
I experiment currently with Nextjs and mongodb and then saw your tutorial, my App is now up and running but nobody can SignUp i get the error
POST https://mausys-web.ivanjeremic.now.sh/api/users 500
mongoURI .env and cloudinary URI are all set and ready to go. any idea whats the problem here? ThanksHere the link to my Site https://mausys-web.ivanjeremic.now.sh/
sometime I get this error also
commons.0be659ca3dbe117d9b15.js:1 POST https://mausys-web.ivanjeremic.now.sh/api/users 502
Error: Connection strategy not found at new MongoStore (D:\Development\Apps\mausys-web\node_modules\connect-mongo\src\index.js:129:15) at useSession (D:\Development\Apps\mausys-web\.next\server\static\QdBxRGfyRVGSOG2ufP6LY\pages\api\session.js:159:10) at middleware (D:\Development\Apps\mausys-web\.next\server\static\QdBxRGfyRVGSOG2ufP6LY\pages\api\session.js:185:55) at Module.V034 (D:\Development\Apps\mausys-web\.next\server\static\QdBxRGfyRVGSOG2ufP6LY\pages\api\users.js:257:146) at __webpack_require__ (D:\Development\Apps\mausys-web\.next\server\static\QdBxRGfyRVGSOG2ufP6LY\pages\api\users.js:23:31) at Object.5 (D:\Development\Apps\mausys-web\.next\server\static\QdBxRGfyRVGSOG2ufP6LY\pages\api\users.js:99:18) at __webpack_require__ (D:\Development\Apps\mausys-web\.next\server\static\QdBxRGfyRVGSOG2ufP6LY\pages\api\users.js:23:31) at D:\Development\Apps\mausys-web\.next\server\static\QdBxRGfyRVGSOG2ufP6LY\pages\api\users.js:91:18 at Object.<anonymous> (D:\Development\Apps\mausys-web\.next\server\static\QdBxRGfyRVGSOG2ufP6LY\pages\api\users.js:94:10) at Module._compile (internal/modules/cjs/loader.js:778:30)
Still can not fix it.