Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update @remap/services #2

Merged
merged 1 commit into from Sep 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Expand Up @@ -19,14 +19,22 @@ module.exports = compose(
)(
async (req, res) => {
// req.auth
// {
// name: string;
// picture: string;
// auth_time: number;
// email: string;
// email_verified: boolean;
// uid: string;
// }
}
)
```

### Optional custom authenticator

```js
const middlwware = authenticateMiddleware({
const middleware = authenticateMiddleware({
authenticate: async () => await doSomething(),
})
```
7 changes: 4 additions & 3 deletions index.js
@@ -1,15 +1,16 @@
const { STATUS_CODES } = require('http')
const { createError } = require('micro-errors')
const { Authentication } = require('@remap/services')
const ReMap = require('@remap/services')

const STATUS_MESSAGE_400 = STATUS_CODES[400]
const STATUS_MESSAGE_401 = STATUS_CODES[401]

const parseAuthToken = auth => auth.trim().split('Bearer ')[1]

module.exports = ({ authenticate = Authentication.authenticate } = {}) => {
module.exports = ({ authenticate } = {}) => {
if (typeof authenticate !== 'function') {
throw new TypeError('`authenticate` service client must be function')
const remap = new ReMap()
authenticate = remap.authenticate.bind(remap)
}

return fn => async (req, res, ...rest) => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -27,13 +27,13 @@
"micro": "^9.0.0"
},
"dependencies": {
"@remap/services": "^1.1.0",
"@remap/services": "^2.0.0",
"micro-errors": "^2.0.0"
},
"devDependencies": {
"ava": "^1.0.0-beta.8",
"cross-fetch": "^2.2.2",
"eslint": "^5.5.0",
"eslint": "^5.6.1",
"eslint-plugin-ava": "^5.1.1",
"eslint-plugin-node": "^7.0.1",
"micro": "^9.3.3",
Expand Down
20 changes: 13 additions & 7 deletions yarn.lock
Expand Up @@ -288,9 +288,9 @@
dependencies:
arrify "^1.0.1"

"@remap/services@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@remap/services/-/services-1.1.0.tgz#8b607075c8225964cb3875c7e77e10b3068de5bb"
"@remap/services@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@remap/services/-/services-2.0.0.tgz#3ec76724937eab7207f0884ac4d62081399d870d"

abbrev@1:
version "1.1.1"
Expand Down Expand Up @@ -911,6 +911,12 @@ debug@^3.1.0:
dependencies:
ms "2.0.0"

debug@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.0.1.tgz#f9bb36d439b8d1f0dd52d8fb6b46e4ebb8c1cd5b"
dependencies:
ms "^2.1.1"

decamelize-keys@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/decamelize-keys/-/decamelize-keys-1.1.0.tgz#d171a87933252807eb3cb61dc1c1445d078df2d9"
Expand Down Expand Up @@ -1110,15 +1116,15 @@ eslint-visitor-keys@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#3f3180fb2e291017716acb4c9d6d5b5c34a6a81d"

eslint@^5.5.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-5.5.0.tgz#8557fcceab5141a8197da9ffd9904f89f64425c6"
eslint@^5.6.1:
version "5.6.1"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-5.6.1.tgz#348134e32ccc09abb2df1bf282b3f6eed8c7b480"
dependencies:
"@babel/code-frame" "^7.0.0"
ajv "^6.5.3"
chalk "^2.1.0"
cross-spawn "^6.0.5"
debug "^3.1.0"
debug "^4.0.1"
doctrine "^2.1.0"
eslint-scope "^4.0.0"
eslint-utils "^1.3.1"
Expand Down