Last active
January 28, 2020 12:48
-
-
Save jdheywood/c7f4b51c9b021da12ce952729ccd4187 to your computer and use it in GitHub Desktop.
Example of simple token authorisation middleware for use in Express application, with unit test (depends on service to get tokens from env vars)
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
const TokenMap = { | |
development: process.env.TOKEN_DEV, | |
staging: process.env.TOKEN_STG, | |
production: process.env.TOKEN_PROD, | |
} | |
export function getAPIAuthToken() { | |
const token = TokenMap[process.env.NODE_ENV]; | |
return token ? token : `no-token-for-env-${process.env.NODE_ENV}`; | |
} | |
export default { getAPIAuthToken }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment