Skip to content
Snippets Groups Projects
Commit 815eefc5 authored by Yannis Barlas's avatar Yannis Barlas
Browse files

docs(middleware): add auth docs to readme

parent d0432f92
No related branches found
No related tags found
No related merge requests found
...@@ -36,6 +36,49 @@ If you place this file in `server/app.js`, starting the server should work autom ...@@ -36,6 +36,49 @@ If you place this file in `server/app.js`, starting the server should work autom
} }
``` ```
### Authorization middleware
The server provides authorization checks through using `graphql-shield`.
You can access all of shield's exports (eg. `rule`, `and`, `or` etc.) through `@coko/server/authorization`.
The only exception is `shield`, which is used internally by the server.
To get started, declare your permissions in any file you want:
```js
// myPermissions.js
const { rule } = require('@coko/server/authorization')
const permissions = {
Query: {
myQuery: rule()(async (parent, args, ctx, info) => {
// my auth logic here
}),
},
Mutation: {
myMutation: rule()(async (parent, args, ctx, info) => {
// my other auth logic here
}),
},
}
module.exports = permissions
```
For the server to access your permissions, simply add them to the config:
```js
// config/default.js
const permissions = require('../path/to/myPermissions.js')
{
permissions: permissions
}
```
Please refer to shield's [documentation](https://github.com/maticzav/graphql-shield#overview) for more details.
### Cron support ### Cron support
All you need for cron-based scheduled tasks to run is to provide the path to your cron jobs. All you need for cron-based scheduled tasks to run is to provide the path to your cron jobs.
...@@ -85,5 +128,5 @@ If you run your client on a different host/port than the server, you might run i ...@@ -85,5 +128,5 @@ If you run your client on a different host/port than the server, you might run i
### Future features ### Future features
- Graphql middleware - Notification middleware
- Include more pubsweet packages into the bundle - Include more pubsweet packages into the bundle
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment