I would like to reproduce how plunker manages anonymous accounts.
Plunker can recognize an anonymous user. For example, we can save the plunker as anonym, and then freeze. As a result
only the same user (before clearing the browser history) has full access to this plunker (for example, save changes, unfreeze).
if the same user opens it in another browser or other users open the same link, they cannot savechange; they owe forkhim.
On my website, I use a strategy local passport.jsfor managing named users. For instance,
router.post('/login', function (req, res, next) {
if (!req.body.username || !req.body.password)
return res.status(400).json({ message: 'Please fill out all fields' });
passport.authenticate('local', function (err, user, info) {
if (err) return next(err);
if (user) res.json({ token: user.generateJWT() });
else return res.status(401).json(info);
})(req, res, next);
});
And I use localStorageto store the token. For instance,
auth.logIn = function (user) {
return $http.post('/login', user).success(function (token) {
$window.localStorage['account-token'] = token;
})
};
auth.logOut = function () {
$window.localStorage.removeItem('account-token');
};
- , passport.js - , , plunker? ?