-
-
Save juodumas/67793c57ebbbde0e5e606b43675dea5e to your computer and use it in GitHub Desktop.
Auth doesn't work with non default local.userEndpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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: 'admin', | |
userEndpoint: '/api/users' | |
}).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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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({local: {userEndpoint: '/api/users'}})) | |
.use(feathers.static(__dirname + '/public')) | |
app.use('/api/users', memoryService({idField: '_id'})) | |
const users = app.service('/api/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(3031) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment