Skip to content

Instantly share code, notes, and snippets.

@snewell92
Created May 26, 2017 13:57
Show Gist options
  • Save snewell92/1691bf026b1912e5f34f63ff96ba0b15 to your computer and use it in GitHub Desktop.
Save snewell92/1691bf026b1912e5f34f63ff96ba0b15 to your computer and use it in GitHub Desktop.
Demonstrate 401 auth problem
const path = require('path');
const favicon = require('serve-favicon');
const compress = require('compression');
const cors = require('cors');
const helmet = require('helmet');
const bodyParser = require('body-parser');
const feathers = require('feathers');
const configuration = require('feathers-configuration');
const hooks = require('feathers-hooks');
const rest = require('feathers-rest');
const socketio = require('feathers-socketio');
const middleware = require('./middleware');
const services = require('./services');
const appHooks = require('./app.hooks');
const authentication = require('./authentication');
const routes = require('./routes');
const app = feathers();
// Load app configuration
app.configure(configuration(path.join(__dirname, '..')));
// Enable CORS, security, compression, favicon and body parsing
app.use(cors());
app.use(helmet());
app.use(compress());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(favicon(path.join(app.get('public'), 'favicon.ico')));
// Host the public folder
app.use('/', feathers.static(app.get('public')));
// Set up Plugins and providers
app.configure(hooks());
app.configure(rest());
app.configure(socketio());
app.configure(authentication);
// Set up our services (see `services/index.js`)
app.configure(services);
app.configure(routes);
// Configure middleware (see `middleware/index.js`) - always has to be last
app.configure(middleware);
app.hooks(appHooks);
module.exports = app;
<html>
<head></head>
<body>
<h3>Oo...</h3>
<p>You cannot see this page friend...</p>
</body>
</html>
<html>
<head></head>
<body>
<h1>Congrats Friend!</h1>
</body>
</html>
<html>
<head></head>
<body>
<form method="POST" action="/login">
<label>Email</label>
<input type="text" name="email"/>
<label>Password</label>
<input type="password" name="password"/>
<input type="submit"/>
</form>
</body>
</html>
const feathers = require('feathers');
const auth = require('feathers-authentication');
module.exports = function () {
const app = this;
app.set('view engine', 'ejs');
app.use(
'/home',
auth.express.authenticate('jwt'),
(req, res, next) => {
console.log("Request for '/home'...");
res.render('home');
}
);
app.use(
'/fail',
(req, res, next) => {
console.log("Request for '/fail'...");
res.render('failure');
next();
}
);
app.post(
'/login',
auth.express.authenticate('local', {
successRedirect: '/home',
failureRedirect: '/fail'
})
);
return app;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment