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

error on call etSessionKey #11

Open
alirayaneh opened this issue Feb 7, 2019 · 14 comments
Open

error on call etSessionKey #11

alirayaneh opened this issue Feb 7, 2019 · 14 comments

Comments

@alirayaneh
Copy link

hi thanks for this modual .
my node -v is 6.9.2
npm -v is 3.10.9
when call to to this propertis .
var sessionKey = laravelSession.getSessionKey(session, laravel_app_key);
it got this error
SyntaxError: Unknown / Unhandled data type(s): � at error (G:\wamp64\www\xxx\laravel\node_modules\php-unserialize\php-unserialize.js:54:13) at _unserialize (G:\wamp64\www\xxx\laravel\node_modules\php-unserialize\php-unserialize.js:166:11) at unserialize (G:\wamp64\www\xxx\laravel\node_modules\php-unserialize\php-unserialize.js:173:10) at Object.getSessionKey (G:\wamp64\www\xxx\laravel\node_modules\node-laravel-session\index.js:46:16) at Namespace.<anonymous> (G:\wamp64\www\xxx\laravel\app.js:28:37) at emitOne (events.js:96:13) at Namespace.emit (events.js:188:7) at Namespace.emit (G:\wamp64\www\xxx\laravel\node_modules\socket.io\lib\namespace.js:205:10) at G:\wamp64\www\xxx\laravel\node_modules\socket.io\lib\namespace.js:172:14 at _combinedTickCallback (internal/process/next_tick.js:67:7) [nodemon] app crashed - waiting for file changes before starting...

@alirayaneh
Copy link
Author

alirayaneh commented Feb 7, 2019

my module version "node-laravel-session": "^2.0.1"
and result of blow command is
console.log(session,laravel_app_key);
result
eyJpdiI6InZFNnFCY2tUZlVPYU9QTGhQd3ZMZUE9PSIsInZhbHVlIjoiU3ZNYTBMSjBFd2NlZmt0TG90RlVwb1lkNmtIUzJcL096WWNVVkNlZVl6dHkzaHVZZGZsaEZtNWNaK0s3ckd2NnhDWjNXbE5DaFJ3SWF3bWM1cWJTbVN3PT0iLCJtYWMiOiJlNTJmMWE2ZjI1YjYyN2FhNzQ4MTQ3ZTc4ZjliZWU2NDcxMjRkOTU3MzVhODI5NTBlNGM2YzZiOGE2OTc4ZTdhIn0=
29A3+reTa/uHap99VMxlpITCLIXIGCJUrnPYkayRyJU

@spearmootz
Copy link
Owner

i dont know what is causing this.

i see the serialized session

}�(���T����V'����H��m �&����H����L�wJ�o�(��g��

and then its trying to unserialize that but it obiously cant.

@alirayaneh
Copy link
Author

i find in this file at line 44
/node_modules/node_laravel_session/index.js

-44 let decoded = decoder.update(laravelSession.value, 'base64'); console.log(decoded);

when print decodde result it return
<Buffer 7d 15 28 f4 03 02 54 f4 07 1a cb 56 27 08 90 ab 85 48 dc f7 6d 20 a9 26 00 80 86 a1 88 48 85 e2 ed 9b c1 4c e4 77 4a a4 6f ac 28 85 ed 67 7f dd>

@spearmootz
Copy link
Owner

spearmootz commented Feb 7, 2019 via email

@alirayaneh
Copy link
Author

alirayaneh commented Feb 7, 2019

i dont know what is causing this.

i see the serialized session

}�(���T����V'����H��m �&����H����L�wJ�o�(��g��

and then its trying to unserialize that but it obiously cant.

I do not know what is this /
this is my code .

var express = require('express');
var app = require('express')();
var http = require('http').createServer(app);
var io = require('socket.io')(http);

var Redis = require("ioredis");
var redis = new Redis();
var laravelSession = require('node-laravel-session');
var cookie = require('cookie');

laravelSession.getAppKey('.env')
.then(function(appKey) {
laravel_app_key=appKey;
});

io.on('connection',function(socket){

var session = cookie.parse(socket.request.headers.cookie).cartbecart_session;
var sessionKey = laravelSession.getSessionKey(session, laravel_app_key);
//console.log(session,laravel_app_key);

.....

@spearmootz
Copy link
Owner

what is the key in the .env file??

@alirayaneh
Copy link
Author

alirayaneh commented Feb 7, 2019

cartbecart_session (laravel_session) eyJpdiI6IlwvQmxPWXlQODc5ZVRUN3czSUYzWlhRPT0iLCJ2YWx1ZSI6IkZUckVBa2thcFwvSDVqUlRGQUw0dWViK25vV21EM3RNb0g5bTFCMzVPSFwvaCsrekZuT05PN2ZWR3RHZmFKXC9DUWR6VHQzc21MeTBiYnB5citZdEpOQVJ3PT0iLCJtYWMiOiI4NWU2ZTJlODFiNWExMTE5YjNkODE3MzMzNzU0ODBjMGU5NzMwZDVlOWZjNmEwZDIxMzQ0OThmNTFhZjk3OGNjIn0=

APP_KEY=base64:29A3+reTa/uHap99VMxlpITCLIXIGCJUrnPYkayRyJU=
generated this new

@spearmootz
Copy link
Owner

i think there might be something wrong with your key because it appears that that is supposed to be base64 encoded but when you go to decode it its malformed

@spearmootz
Copy link
Owner

if you are still in development try to regenerate it

@alirayaneh
Copy link
Author

if you are still in development try to regenerate it

I did this several times with the following command
php artisan key:gen

@spearmootz
Copy link
Owner

ok, so it had been a while since i played with laravel so.... i did some testing and got the same error here. now i think i was able to fix it but i would like to verify with you....

could you add the following log

console.log('decodedValue', decoded.toString());

and you will get a weird string (in your case it had symbols, in mine it didnt, i dont know if it has to do something with the character encoding. If you have a different character encoding pass it to the function toString like so "toString('utf-8')")

once you do, get the value it logs and try to look for that key in you session driver, if its a file it will be in the storage folder and if its in a database or redis it will be the primary key or identifier of the session.

if you confirm i will create a fix and push it :)

@alirayaneh
Copy link
Author

ok .. i will come back soon

@alirayaneh
Copy link
Author

i add this line in /node_modules/node_laravel_session/index.js after line 43

result is

decodedValue s:40:"3EyeQWEP03dudZvuE1PpoaXxXVb6gskywKYQo2FW";

@alirayaneh
Copy link
Author

wow problem was solved

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

2 participants