sysgears / apollo-universal-starter-kit

Apollo Universal Starter Kit is a SEO-friendly, fully-configured, modular starter application that helps developers to streamline web, server, and mobile development with cutting-edge technologies and ultimate code reuse.
https://apollokit.org
MIT License
1.68k stars 324 forks source link

TypeError: Cannot read property 'password' of undefined #345

Closed mairh closed 7 years ago

mairh commented 7 years ago

Just took a fresh copy of the kit

yarn and yarn seed and yarn watch

backend error TypeError: Cannot read property 'password' of undefined
    at Object._callee2$ (/Users/nish/Documents/apollo-universal-starter-kit/src/server/modules/user/auth.js:42:1)
    at tryCatch (/Users/nish/Documents/apollo-universal-starter-kit/node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:65:40)
    at Generator.invoke [as _invoke] (/Users/nish/Documents/apollo-universal-starter-kit/node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:299:22)
    at Generator.prototype.(anonymous function) [as next] (/Users/nish/Documents/apollo-universal-starter-kit/node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:117:21)
    at step (/Users/nish/Documents/apollo-universal-starter-kit/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /Users/nish/Documents/apollo-universal-starter-kit/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
    at <anonymous>
mitjade commented 7 years ago

@mairh Does not happen to me? Can you try to delete the dev-db.sqlite3, run yarn seed and try again?

semyenov commented 7 years ago

Maybe it's not related to this error, but check out this lines https://github.com/sysgears/apollo-universal-starter-kit/blob/7f9a7a2e61ba6df4761d67ba2749fd553fed9584/src/server/modules/user/token.js#L22 and https://github.com/sysgears/apollo-universal-starter-kit/blob/7f9a7a2e61ba6df4761d67ba2749fd553fed9584/src/server/modules/user/token.js#L46 looks like a typo

mitjade commented 7 years ago

@semyenov First one is a typo, should be fixed. Where is the problem on line 46?

mitjade commented 7 years ago

@semyenov Seem this line is not needed and can be removed.

semyenov commented 7 years ago

@mitjade https://github.com/sysgears/apollo-universal-starter-kit/blob/7f9a7a2e61ba6df4761d67ba2749fd553fed9584/src/server/modules/user/token.js#L46 header syntax is Access-Control-Allow-Origin: <origin> | * 'true' will cause connection error

mitjade commented 7 years ago

@semyenov This is already taken care of with CORS, so I will just remove it. Thank you for pointing it out.

semyenov commented 7 years ago

@mitjade thx for your work

larixer commented 7 years ago

@mairh Have you tried to recreate your database as was suggested by @mitjade ?

mairh commented 7 years ago

closing because it seems like the database was corrupted on the laptop. I tried with another laptop and it works fine.

mairh commented 7 years ago

@vlasenko @mitjade Reopening since I am getting the same error after recreating the database file.

Note: Mobile build is fine and I can see the app on expo

larixer commented 7 years ago

@mairh Can you figure out reproduction steps for this one?

mairh commented 7 years ago

1) Fresh clone the repo 2) Run yarn 3) Run yarn seed 4) Run yarn watch

screen shot 2017-09-12 at 15 10 34

~/Documents/apollo-universal-starter-kit(master*) ยป yarn                                                                                                                                                                                                                                                                                       nish@Ujjwals-MacBook-Pro-2
yarn install v1.0.1
[1/5] ๐Ÿ”  Validating package.json...
[2/5] ๐Ÿ”  Resolving packages...
[3/5] ๐Ÿšš  Fetching packages...
[4/5] ๐Ÿ”—  Linking dependencies...
warning "babel-loader@7.1.2" has incorrect peer dependency "babel-core@6 || 7 || ^7.0.0-alpha || ^7.0.0-beta || ^7.0.0-rc".
warning "ajv-keywords@1.5.1" has incorrect peer dependency "ajv@>=4.10.0".
warning "superagent-retry@0.6.0" has incorrect peer dependency "superagent@*".
warning "superagent-proxy@1.0.2" has incorrect peer dependency "superagent@>= 0.15.4 || 1 || 2 || 3".
warning "haul@1.0.0-beta.5" has incorrect peer dependency "babel-preset-react-native@^2.0.0".
warning "babel-loader@6.4.1" has incorrect peer dependency "babel-core@^6.0.0".
warning "babel-loader@6.4.1" has incorrect peer dependency "webpack@1 || 2 || ^2.1.0-beta || ^2.2.0-rc".
warning "request-promise-native@1.0.4" has incorrect peer dependency "request@^2.34".
warning "request-promise-core@1.1.1" has incorrect peer dependency "request@^2.34".
warning "mocha-webpack@0.7.0" has incorrect peer dependency "webpack@^1.12.13 || ^2.1.0-beta.15".
warning "ajv-keywords@2.1.0" has incorrect peer dependency "ajv@>=5.0.0".
[5/5] ๐Ÿ“ƒ  Building fresh packages...
โœจ  Done in 27.20s.
------------------------------------------------------------
~/Documents/apollo-universal-starter-kit(master*) ยป yarn seed                                                                                                                                                                                                                                                                                  nish@Ujjwals-MacBook-Pro-2
yarn seed v1.0.1
$ npm run migrate && knex seed:run

> apollo-universal-starter-kit@1.0.0 migrate /Users/nish/Documents/apollo-universal-starter-kit
> knex migrate:latest

Using environment: development
Batch 1 run: 3 migrations
/Users/nish/Documents/apollo-universal-starter-kit/src/server/database/migrations/counter.js
/Users/nish/Documents/apollo-universal-starter-kit/src/server/database/migrations/post.js
/Users/nish/Documents/apollo-universal-starter-kit/src/server/database/migrations/user.js
yarn waUsing environment: development
tchRan 3 seed files
/Users/nish/Documents/apollo-universal-starter-kit/src/server/database/seeds/counter.js
/Users/nish/Documents/apollo-universal-starter-kit/src/server/database/seeds/post.js
/Users/nish/Documents/apollo-universal-starter-kit/src/server/database/seeds/user.js
โœจ  Done in 5.00s.
------------------------------------------------------------
~/Documents/apollo-universal-starter-kit(master*) ยป yarn watch                                                                                                                                                                                                                                                                                 nish@Ujjwals-MacBook-Pro-2
yarn watch v1.0.1
$ spin watch
Generating vendor_web DLL bundle with modules:
["apollo-client","apollo-logger","bootstrap","cors","graphql","graphql-iso-date","graphql-tag","history","immutability-helper","jwt-decode","lodash","minilog","persistgraphql","prop-types","react","react-apollo","react-cookie","react-dom","react-ga","react-helmet","react-hot-loader","react-redux","react-router","react-router-dom","react-router-redux","react-transition-group","reactstrap","redux","redux-devtools-extension","redux-form","styled-components","subscriptions-transport-ws"]
Generating vendor_ios DLL bundle with modules:
["@expo/vector-icons","apollo-client","apollo-logger","cors","expo","graphql","graphql-iso-date","graphql-tag","immutability-helper","lodash","minilog","prop-types","react","react-apollo","react-native","react-navigation","redux","subscriptions-transport-ws","/Users/nish/Documents/apollo-universal-starter-kit/node_modules/spinjs/lib/plugins/react-native/react-native-polyfill.js"]
webpack-for-webDll Time: 27745ms
[HPM] Proxy created: !/*.hot-update.{json,js}  ->  http://172.31.99.227:8080
webpack-for-web Webpack web dev server listening on http://172.31.99.227:3000
webpack-for-iosDll Time: 34889ms
webpack-for-ios Webpack ios dev server listening on http://172.31.99.227:3020
webpack-for-web debug Webpack dev server is waiting for backend to start...
webpack-for-server Starting backend
webpack-for-server Time: 52257ms
backend info API is now running on port 8080
webpack-for-ios debug Webpack dev server is waiting for backend to start...
webpack-for-ios debug Backend has been started, resuming webpack dev server...
webpack-for-web debug Backend has been started, resuming webpack dev server...
webpack-for-ios bundle is now VALID.
webpack-for-ios Time: 20063ms
webpack-for-web bundle is now VALID.
webpack-for-web Time: 28166ms
backend error TypeError: Cannot read property 'password' of undefined
    at Object._callee2$ (/Users/nish/Documents/apollo-universal-starter-kit/src/server/modules/user/auth.js:42:1)
    at tryCatch (/Users/nish/Documents/apollo-universal-starter-kit/node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:65:40)
    at Generator.invoke [as _invoke] (/Users/nish/Documents/apollo-universal-starter-kit/node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:299:22)
    at Generator.prototype.(anonymous function) [as next] (/Users/nish/Documents/apollo-universal-starter-kit/node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:117:21)
    at step (/Users/nish/Documents/apollo-universal-starter-kit/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /Users/nish/Documents/apollo-universal-starter-kit/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
    at <anonymous>
Expo address for ios: exp://172.31.99.227:19001
To open this app on your phone scan this QR code in Expo Client (if it doesn't get started automatically)
larixer commented 7 years ago

@mairh Under what user are you logging in after yarn watch ?

mairh commented 7 years ago

I didn't login. The website wouldn't open.

mairh commented 7 years ago

Ok. I got it now. After cleaning the browser cache it is working now. Let me dig deeper and reproduce the error in the exact scenario.

mairh commented 7 years ago

ok. so here it goes. I am not sure what we can do about it

1) Register a new user 2) Populate the seed again after removing the database 3) Run yarn watch 4) Since the cookie still has my old user info in the browser I can't open the website. Although, the database does not contain my user info anymore.

I believe I had created a new user in the kit (on the local machine). I had some problem with yarn.lock file and thus I did a fresh clone of the kit. Ran the usual steps, but didn't have my old register user info in the DB (but it was saved in the browser).

mairh commented 7 years ago

It may happen in the production env too. Let's say a user is created in the prod env. Someone deleted the user info from DB and thus the same user tries to open the website resulting in crashing the server since the user does not exist in the DB anymore.

larixer commented 7 years ago

@mairh Yes, in case cookie is invalid or user from cookie cannot be found in database, we should treat this situation as user is not logged in

mairh commented 7 years ago

That's right.

larixer commented 7 years ago

I have committed workaround. But general error handling should be improved on all levels in Auth module

ghost commented 4 years ago

body-parser install for this solution

ghost commented 4 years ago

body-parser install for this solution in node package