Skip to content

Commit a2a8a1b

Browse files
committed
📝 Document auth decorators usage
1 parent 7bd4855 commit a2a8a1b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/AUTH.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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(({ args }) =>
13+
Promise.resolve({
14+
or: [
15+
{ type: 'global', permission: P.global.VIEW_ANY_PLAN_DATA },
16+
{ type: 'plan', permission: P.plan.VIEW_DATA, id: args.id },
17+
],
18+
})
19+
)
20+
```
21+
22+
If only global permission check is needed, it can be used directly:
23+
24+
```lang=js
25+
@Permission({
26+
type: 'global',
27+
permission: P.global.VIEW_ALL_JOBS,
28+
})
29+
```

0 commit comments

Comments
 (0)