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

app fails when todo is added #38

Open
sfthurber opened this issue Jun 2, 2018 · 3 comments
Open

app fails when todo is added #38

sfthurber opened this issue Jun 2, 2018 · 3 comments

Comments

@sfthurber
Copy link

sfthurber commented Jun 2, 2018

i'm using a windows 10 machine and experiencing app failure when a todo is added.

here is the console:
Asset Size Chunks Chunk Names
bundle.js 2.58 MB 0 [emitted] [big] bundle
bundle.css 5.89 kB 0 [emitted] bundle
bundle.js.map 2.81 MB 0 [emitted] bundle
bundle.css.map 16.5 kB 0 [emitted] bundle
webpack: Compiled successfully.
ERR
ERR ValidationError: createdBy: Cast to ObjectID failed for value "{}" at path "createdBy"
at new ValidationError (C:\Users\user\mobx1\node_modules\mongoose\lib\error\validation.js:28:11)
at model.Document.invalidate (C:\Users\user\mobx1\node_modules\mongoose\lib\document.js:1612:32)
at model.Document.set (C:\Users\user\mobx1\node_modules\mongoose\lib\document.js:761:10)
at model._handleIndex (C:\Users\user\mobx1\node_modules\mongoose\lib\document.js:594:14)
at model.Document.set (C:\Users\user\mobx1\node_modules\mongoose\lib\document.js:554:24)
at model.Document (C:\Users\user\mobx1\node_modules\mongoose\lib\document.js:73:12)
at model.Model (C:\Users\user\mobx1\node_modules\mongoose\lib\model.js:47:12)
at new model (C:\Users\user\mobx1\node_modules\mongoose\lib\model.js:3698:13)
at C:/Users/user/mobx1/server/routes/todos.js:22:19
at new Promise ()
at addTodos (C:/Users/user/mobx1/server/routes/todos.js:17:8)
at dispatch (C:\Users\user\mobx1\node_modules\koa-router\node_modules\koa-compose\index.js:44:32)
at next (C:\Users\user\mobx1\node_modules\koa-router\node_modules\koa-compose\index.js:45:18)
at C:\Users\user\mobx1\node_modules\koa-router\lib\router.js:346:16
at dispatch (C:\Users\user\mobx1\node_modules\koa-router\node_modules\koa-compose\index.js:44:32)
at C:\Users\user\mobx1\node_modules\koa-router\node_modules\koa-compose\index.js:36:12

(NOTE: i registered and logged in first)

console message (from the code below) shows ctx.account.id is undefined and account.token is ok.

`export async function login(ctx) {
const { username, password } = ctx.request.fields
const account = await Account.findOne({
username,
password: sha512(password, { salt: username })
})
if (!account) throw new Exception('Wrong credentials')

account.token = createAuthToken(account._id)
await account.save()

ctx.cookies.set('token', account.token)
ctx.body = account.toJSON()
console.info('Logged-in context '+ ctx.account.id + ' ' + account.token)
}`

``

@TobiasKrogh
Copy link

experiencing the same issue on MacOS

  • cloned repository
  • mongodb is running
  • registered / logged in
  • when adding todo I see the same error message

anyone came across this and was able to fix it?

@sfthurber sfthurber changed the title on windows, app fails when todo is added app fails when todo is added Jun 20, 2018
@Xilonz
Copy link

Xilonz commented Nov 27, 2018

I was experimenting with this starter kit as well.
Changes:

  • src/config/context.js line 7 to const request = requestCreator(state)
  • core/request.js replace token with state.account.token

Reason: The variable token was initialized on pageload and not in the mobx-observable anymore, so it wouldn't change when the user logs in.

Have fun!

@MikeBendorf11
Copy link

Thanks, great example!
In case anybody wondering how the newest package.json file should look like
https://github.com/MikeBendorf11/mobx-intro-starter

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

No branches or pull requests

4 participants