Skip to content

Commit 414bc19

Browse files
committed
📝 Document auth decorators usage
1 parent c956cfb commit 414bc19

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/AUTH.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Authentication
2+
3+
Authentication can be used as a guard on a field, query or mutation, restricting data access or actions for a specific group of users.
4+
5+
Since the codebase uses TypeGraphQL, which relies heavily on decorators, authentication is also done using decorators.
6+
7+
Authentication is done with use of `@Permission` decorator. This decorator takes function as an argument with permission object as a return value.
8+
9+
For example:
10+
11+
```lang=js
12+
@Permission(async (resolverData) => ({
13+
or: [
14+
{
15+
type: 'global',
16+
permission: 'viewOperationMetadata',
17+
},
18+
{
19+
type: 'operation',
20+
permission: 'canViewMetadata',
21+
id: 11,
22+
},
23+
],
24+
}))
25+
```
26+
27+
In this example, `id` field is hardcoded for demo purposes, but `resolverData` can be used to obtain the actual value.

0 commit comments

Comments
 (0)