html - node.js, socket.io - Web site architecture -


i have web site in i'd have user system user logged in no matter on web site.

using socket.io, found each html page requires own socket.io connection. every time user leaves 1 html page another, disconnect first socket , connect other.

what best way preserve such connection? don't want user manually log in on every html page. i'd assume passing login data html parameters , automatically log in server parameters extremely dumb, solution can think of.

ideally, socket.io use same socket on entire site.

i assume i'm missing though, considering websites user system has desired functionality.

two things important here:

  • socket reset and
  • authentication.

socket disconnect

if leave page, disconnect. period. cannot change that, , if pages distinct, sockets reconnected each time. 1 way work around problem create instead spa - single page application framework angular or ember. it's client side routing - catch clicks , show different "pages" without reloading. in addition keeping socket open, benefit of not having reload shared assets, network overhead etc, beneficial on mobile devices.

but don't have to.

authentication

as others have suggested, actual problem auth mechanism isn't doing enough. if socket gets reset, new socket needs re-authenticated. there libraries can work, or yourself. can simple picking cookie or sort of auth token got on first auth send socket connect (if it's present). , authentication done against value.

with auth set that, can share auth between regular , socket calls , stay authenticated on pages , page reloads.


Comments