# Share session between Node.js and Rails

**URL:** <https://www.ruby-forum.com/t/share-session-between-node-js-and-rails/195969>\
**Category:** Rails\
**Created:** [October 4, 2010, 1:27pm UTC](https://www.ruby-forum.com/t/share-session-between-node-js-and-rails/195969 "2010-10-04T13:27:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dazuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d6d6ee/32.png) [@dazuma](https://www.ruby-forum.com/u/dazuma)\
**Post date:** [October 4, 2010, 1:27pm UTC](https://www.ruby-forum.com/t/share-session-between-node-js-and-rails/195969/1 "2010-10-04T13:27:35Z")

</div>

Hi!

I’m not an expert on Rails, but I’ve been doing some recent  
development with it. Right now, I have a working app with devise for  
authentication.

Moreover, I am building a chat with Node.js and [Socket.io](http://Socket.io) and I wanted  
to embed the client side of the Node.js app in my Rails app, in order  
to let users access the Rails app and then chat without having to  
authenticate again for Node.

Is there any way to do that and at the same time be able to retrieve  
the current\_username from the rails database?

Thanks

---

<div class="post-metadata">

**Author:** ![dazuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d6d6ee/32.png) [@dazuma](https://www.ruby-forum.com/u/dazuma)\
**Post date:** [October 5, 2010, 4:26pm UTC](https://www.ruby-forum.com/t/share-session-between-node-js-and-rails/195969/2 "2010-10-05T16:26:31Z")

</div>

Daniel A. wrote:

> Hi!
> 
> I’m not an expert on Rails, but I’ve been doing some recent  
> development with it. Right now, I have a working app with devise for  
> authentication.
> 
> Moreover, I am building a chat with Node.js and [Socket.io](http://Socket.io) and I wanted  
> to embed the client side of the Node.js app in my Rails app, in order  
> to let users access the Rails app and then chat without having to  
> authenticate again for Node.
> 
> Is there any way to do that and at the same time be able to retrieve  
> the current\_username from the rails database?

I have two thoughts here, though I know nothing about Node.js and little  
about Ajax authentication:

1. Can you have Rails set a cookie and the JavaScript app read it (or  
vice versa)?

2. Perhaps _neither_ the Rails app nor the JS app should do the  
authentication lookup. You might want to build a third app (probably a  
Rails REST service) that handles the lookup and gives back a token of  
some sort. Rails can use it through ActiveResource, and the JS app can  
use it through an Ajax call.

> Thanks

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
