Skycap
Drop-in authentication and authoriztion framework for Express.js
NO OFFICIAL RELEASE YET
Although I am using Skycap in a few of my own projects, it's not quite ready for use yet, and is not supported. Don't use this in your project yet! :)
Installation
Install skycap with NPM:
npm install skycap --save
Install the Skycap adapter of your choice (Knex.js in this example):
npm install skycap-adapter-knex --save
Require it in your Express.js Node service, and mount it with app.use
:
// Require Skycap + Your Adapterconst skycap = ;const skycapKnex = ; // Skycap custom configconst skycapConfig = brand: name: 'MySite, Inc.' href: '/' css: '/css/bootstrap.min.css' '/css/main.css' js: '/js/yayquery.js' fields: username: true // false by default (email-only login) hooks: { // after successful user registration // Add user's email to a mailing list? Maybe? Dunno. return user; // Don't forget to return the user object! } authAfterLogin: undefined // after successful user login userFormat: undefined // Format the user object from raw data redirects: loginSuccess: '/dashboard' registerSuccess: '/dashboard/?newuser=true' ; // Set your Knex.js connection instanceskycapKnex; // Where 'knex' is your Knex.js connection // Mount Skycap with Express.jsapp;
Database Migrations
If you are using Skycap with Knex.js (via the skycap-adapter-knex
package),
generate a new migrate file via knex migrate:make skycap
, and put this in
it:
const normalizedPath = ;let migrates = ; // Require all migrations in Skycap; exports { // Up in ORDER return Promiseallmigrates;}; exports { // Down in REVERSE ORDER return Promiseallmigrates;};
Usage
Once configured, use Skycap provided middleware in your Express.js routes to
enforce user logins with loadUser
, requireUser
, or requireAdmin
:
const loadUser requireUser requireAdmin = middleware; app; app; app;
Usage With an API
Skycap detects the request Content-Type
, and responds with JSON for API
requests with application/json
, and HTML and redirects for text/html
requests.