usay-app-core v1.0.39
Usay NodeJS Core for Front-ends
Publishing changes
cd ~/Sites/package-app-core && npm version patch && git push
Installing
npm install git+ssh://git@bitbucket.org/usaycomparedev/package-app-core.git#v1.0.1
Updating
npm install git+ssh://git@bitbucket.org/usaycomparedev/package-app-core.git#v1.0.2
This package will serve as a package for common features shared across our NodeJS front-end applications.
What does it provide?
Authentication Middleware
Authentication middleware is provided out of the box. To make use of the middleware on your routes, you can do the following:
// Require our package
const usay = require('usay-app-core');
// Create a protected route
app.get('/', usay.checkAuth, (req, res) => { res.send("I'm protected!") });
// Create an unprotected route
app.get('/foo', usay.checkAuth, (req, res) => { res.send("I'm open to the world!") });
For the authentication middleware to work correctly, you must also setup a route that will handle the redirect back from our authentication server. To do this, simply setup an unprotected /setToken
route that calls the usay.setCookie()
function like this:
// This is set to handle the redirect back from the auth manager
app.get('/setCookie', (req, res) => usay.setCookie(req, res));
Session Setup
The package also provides a very simple way of getting up and running with redis sessions. Setup your session like so:
// Require our package
const usay = require('usay-app-core');
// Initialise the session (if you're using express.static(), it should be above this statement as to not cause issues)
app.use(usay.session());
// Test if it's working on a protected route so we'll have session data to display
app.get('/session-test', usay.checkAuth, (req, res) => { console.log(req.session) });
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago