Created
April 6, 2017 20:59
-
-
Save marshallswain/d4ea6a02fcd4be778c022c8dd457f225 to your computer and use it in GitHub Desktop.
FeathersJS: Set up and endpoint to handle "mixed auth"
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
'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