scookie
scookie helps you securely persist JSON data to HTTP cookies for user login
Installation
npm
npm install scookie
GitHub
npm install https://github.com/martinrue/scookie/tarball/master
Initialisation
Call init
to set the name of the cookie, the cookie secret, the unauthorised redirect URL and the cookie age (ms):
scookie;
Login
Call login
to issue a cookie containing data about the user:
var user = id: 1 username: 'martin' name: 'Martin Rue' ;scookie;
response
should be a connect
-based HTTP response object capable of setting a response cookie. For example, the response
object provided by both connect
and express
handlers will work fine.
Logout
Call logout
to clear any issues cookies:
scookie;
Get User Data
To retrieve data about the current session from the cookie, call getCookie
:
var cookie = scookie;
Check User Login
To determine if a login cookie has been issued, call isLoggedIn
:
if scookie // client has untampered cookie set
Connect Middleware
To avoid constantly checking isLoggedIn
, you can use the middleware function instead:
app;
Express Example App
var http = ;var express = ;var scookie = ; var app = ;var server = http; app; scookie; app; app; app; server;