How to save php session in Mongodb and recover data in Nodejs

Asked

Viewed 160 times

1

I’m running a server on php and another in nodejs trying to get a simple authentication since every session runs in php and nodejs simply processes some events however, and required authentication as I can do with Mongodb (drive php)?

I tried with memcache (php and Node) but did not succeed since memcache dll for php7 is still in status dev (development).

  • I assume you’re running PHP and Node on the same machine with both of you accessing Mongodb, right? Can you clarify this and also correct some spelling errors? Interesting question, +1.

  • Yes, exactly that. The project itself is a php website and features like chat, plugins and nodejs apps.

1 answer

0

Instead of session, you can use the default JWT of tokens, you will already find ready material in several languages.

For example, in the login you can generate the token, and check it on another machine, without needing access to the bank. This is perfect for scalability, as several servers can validate the token without talking to each other. It is only necessary that the two use the same key.

The JWT token may contain information such as the user ID, and also has an expiration date, which will be respected at the time of validation.

  • I used jwt with socket.io but now I’m using express4 with Passport-local and espress-Session and the idea would no longer pass parameters like user id or session via query-string but a token created in php and saved (with php) in the Mongodb database and recover it (using token). Node would only receive the token via query-string and search for the reference in Mongodb (with mongodb or Mongoose) to find this Session and use in Node (express-Session).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.