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

Cookie StateSource Error: req is required #276

Closed
Gugudesaster opened this issue Apr 13, 2015 · 4 comments
Closed

Cookie StateSource Error: req is required #276

Gugudesaster opened this issue Apr 13, 2015 · 4 comments

Comments

@Gugudesaster
Copy link

Getting error when I try to require a cookie StateSource.

 Error: req is required
     at Object.ServerCookies (/var/www/testapp/node_modules/marty-express/serverCookies.js:3:11)
     at /var/www/testapp/node_modules/marty-express/index.js:22:12
     at Class.CookieStateSource (/var/www/testapp/node_modules/marty/dist/node/lib/stateSource/inbuilt/cookie.js:20:21)
     at new Class (/var/www/testapp/node_modules/marty/dist/node/lib/createClass.js:14:10)
     at Registry.resolve (/var/www/testapp/node_modules/marty/dist/node/lib/registry.js:108:16)
     at /var/www/testapp/node_modules/marty/dist/node/lib/context.js:38:52
     at baseFor (/var/www/testapp/node_modules/lodash/internal/baseFor.js:23:9)
     at baseForOwn (/var/www/testapp/node_modules/lodash/internal/baseForOwn.js:14:10)
     at baseEach (/var/www/testapp/node_modules/lodash/internal/baseEach.js:17:12)
     at Object.forEach [as each] (/var/www/testapp/node_modules/lodash/collection/forEach.js:39:7)

this is my sessionCookieAPI.js:

var Marty = require('marty');

 var SessionCookieAPI = Marty.createStateSource({
   id: 'SessionCookieAPI',
   type: 'cookie',

   login: function (token) {
     this.set('token', token);
   },
   logout: function() {
     this.expire('token');
   },
   isLoggedIn: function () {
     return !!this.get('token');
   },
   getToken: function () {
     return this.get('token');
   },
 });

module.exports = SessionCookieAPI;

requiring it is enough to trigger this error. No need to call an action

  var SessionCookieAPI = require('../sources/sessionCookieAPI');
@jhollingworth
Copy link
Contributor

ah, damn. I know what this is. I will try and fix ASAP

@jhollingworth
Copy link
Contributor

This should be fixed now. Closing.

@Gugudesaster
Copy link
Author

now i updated to 0.9.14 and tried to test it again with the same sessionCookieAPI.js as above. but now I always get:
Warning: Could not find cookies in req. Do you have the cookie-parser middleware (https://www.npmjs.com/package/cookie-parser) installed?

I do have cookie-parser in my package.json and it is in the node-modules folder. still I get this error.
this is my default.js (the root route file where I do the account handling): https://gist.github.com/Gugudesaster/9bf0e55d7da0777356f6

This is the accountStore.js: https://gist.github.com/Gugudesaster/771f16967e06d3ddfe27

i've been trying to solve this for hours now, but can't seem to get it working. is it a bug or am i requesting the cookie too early in the application? where else would i put my authentication?
maybe it's because of me using sessioncookieapi in the store to get the current jwt token?

@taion
Copy link
Member

taion commented May 14, 2015

Are you actually using the cookie-parser middleware? https://www.npmjs.com/package/cookie-parser#api

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

3 participants