john smith
john smith

Reputation: 2153

Node.JS notifications on my PHP based website

I am developing a website in PHP. Now, I would like to simply add a notification system. Imagine it like Facebook friendships: when I get a friend request, I get a notification too.

I of course know a bit of Node.JS and Socket.IO, but the tricky part seems to be the implementation with PHP.

What I though of so far is:

1. user sends friend request
2. in my PHP code, I cURL my Node.JS service: "/notification?friendid=9634963478"
3. user with id 9634963478 should get a notification

The problem I am facing is:

How do I "log in" with the same credentials on Node.js? So that Basically no other user than me can get the messages?

I am not looking for code, but rather an "enlightenment" from some guru out there.

Upvotes: 4

Views: 576

Answers (1)

chovy
chovy

Reputation: 75774

use the same session store backend in your nodejs app and pass the cookie along, it would have to be on the same subdomain, for example msg.example.com where the cookie is set by your php layer on .example.com

Look at express.session -- here's an example using redis:

      var RedisStore = require('connect-redis')(express);

      app.use(express.session({
        store: new RedisStore({
          host: cfg.redis.host,
          db: cfg.redis.db
        }),
        secret: 'foobar'
      }));

A video about using sessions: http://nodetuts.com/tutorials/13-authentication-in-express-sessions-and-route-middleware.html

Upvotes: 1

Related Questions