Skip to content

Instantly share code, notes, and snippets.

@juodumas
Created April 14, 2016 10:05
Show Gist options
  • Save juodumas/ef831aa1f595e7745d7e418108bea461 to your computer and use it in GitHub Desktop.
Save juodumas/ef831aa1f595e7745d7e418108bea461 to your computer and use it in GitHub Desktop.
feathers-rest returns Internal Server Error on invalid login
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script src="socket.io/socket.io.js"></script>
<script src="primus/primus.js"></script>
<script src="//cdn.rawgit.com/feathersjs/feathers-client/v1.1.0/dist/feathers.js"></script>
<script>
function feathersTransportTest(transport) {
var app = feathers()
app.configure(feathers.hooks())
app.configure(feathers.authentication({storage: window.localStorage}))
if (transport == 'rest') {
app.configure(feathers.rest().fetch(window.fetch.bind(window)))
}
else if (transport == 'socketio') {
var socket = io()
app.configure(feathers.socketio(socket))
}
else {
primus = new Primus()
app.configure(feathers.primus(primus))
}
app.authenticate({
type: 'local',
email: 'admin',
password: 'admins'
}).then(function(r) {
console.log(`${transport}:auth`, r)
}).catch(function(r) {
console.log(`${transport}:auth-error`, r)
})
}
feathersTransportTest('rest')
feathersTransportTest('socketio')
feathersTransportTest('primus')
</script>
</body>
</html>
// npm init --yes
// npm i feathers feathers-memory feathers-authentication feathers-hooks feathers-rest feathers-socketio feathers-primus body-parser
const bodyParser = require('body-parser')
const feathers = require('feathers')
const hooks = require('feathers-hooks')
const rest = require('feathers-rest')
const socketio = require('feathers-socketio')
const primus = require('feathers-primus')
const authentication = require('feathers-authentication')
const memoryService = require('feathers-memory')
const app = feathers()
.configure(rest())
.configure(socketio())
.configure(primus({transformer: 'websockets'}))
.configure(hooks())
.use(bodyParser.json())
.use(bodyParser.urlencoded({extended: true}))
.configure(authentication())
.use(feathers.static(__dirname + '/public'))
app.use('users', memoryService())
const users = app.service('users')
users.before({
create: authentication.hooks.hashPassword('password'),
update: authentication.hooks.hashPassword('password'),
patch: authentication.hooks.hashPassword('password')
})
users.create({
id: 'admin',
email: 'admin',
password: 'admin'
})
app.listen(3030)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment