Last active
July 28, 2017 14:45
-
-
Save stalniy/f648d6644afb02bb61abdce7ed81edf5 to your computer and use it in GitHub Desktop.
Feathers authentication with silent errors
This file contains hidden or 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
| 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