Skip to content

Instantly share code, notes, and snippets.

@stalniy
Last active July 28, 2017 14:45
Show Gist options
  • Select an option

  • Save stalniy/f648d6644afb02bb61abdce7ed81edf5 to your computer and use it in GitHub Desktop.

Select an option

Save stalniy/f648d6644afb02bb61abdce7ed81edf5 to your computer and use it in GitHub Desktop.
Feathers authentication with silent errors
const { authenticate } = require('feathers-authentication').hooks
const { NotAuthenticated } = require('feathers-errors')
const verifyIdentity = authenticate('jwt')
function hasToken(hook) {
return hook.params.headers.authorization || hook.data.accessToken
}
module.exports = async function authenticate(hook) {
try {
return await verifyIdentity(hook)
} catch (error) {
if (error instanceof NotAuthenticated && !hasToken(hook)) {
return hook
}
throw error
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment