baucis-decorator-guests
v1.0.1
Published
Automatically creates unauthenticated users as guests and reserves guest names.
Downloads
10
Maintainers
Readme
baucis-decorator-guests
Automatically creates unauthenticated users as guests and reserves guest names.
Install
npm install baucis-decorators baucis-decorator-guests --save
Usage
Just add the decorator with your Express app instance and it should work. Works with baucis-decorator-auth
, so using mongoose
as your session store may be required.
Example
controllers/User.js
var baucis = require('baucis');
var ResourceController = require('../controllers/Resource.js');
// ensure model is initialized
var UserModel = require('../models/User.js');
var UserController = baucis.rest('User');
var decorators = require('baucis-decorators');
var guests = require('baucis-decorator-guests');
var app = require('../server/app.js');
// decorate controller
decorators.add.call(UserController, [
guests(app), // upon every request, creates a guest `User` if `req.session.userId` is undefined
ResourceController // `UserController` will inherit all of `ResourceController`'s decorators
]);
/**
* Expose controller.
*/
module.exports = UserController;