Skip to content

Instantly share code, notes, and snippets.

@marshallswain
Created April 6, 2017 20:59
Show Gist options
  • Save marshallswain/d4ea6a02fcd4be778c022c8dd457f225 to your computer and use it in GitHub Desktop.
Save marshallswain/d4ea6a02fcd4be778c022c8dd457f225 to your computer and use it in GitHub Desktop.
FeathersJS: Set up and endpoint to handle "mixed auth"
'use strict';
const { authenticate } = require('feathers-authentication').hooks;
const { hashPassword } = require('feathers-authentication-local').hooks;
// Bring in the `iff` hook.
const { iff } = require('feathers-hooks-common');
module.exports = {
before: {
find: [
// If a token was included, authenticate it with the `jwt` strategy.
iff(
hook => hook.params.token,
authenticate('jwt')
// No token was found, so limit the query to include `public: true`
).else( hook => Object.assign(hook.params.query, { public: true }) )
]
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment