Skip to content

Commit 1647bf2

Browse files
authored
Merge pull request #400 from devforth/AdminForth/933
docs: add docs foir the adminUserAuthorize hook
2 parents 6bf1a19 + d011327 commit 1647bf2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

adminforth/documentation/docs/tutorial/03-Customization/12-security.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,31 @@ So to completely hide the email field from all users apart superadmins, you shou
209209
```
210210
211211
So if you will configure the email column in user resource like this, only superadmin will be able to see emails, and only in the list view.
212+
213+
## Custom user authorization hook
214+
215+
Default user authorization checks that cookie with JWT token is valid, signed and not expired.
216+
You can use custom hook to decide whether to allow exections of all default and cusotm API endpoints (wraped by authorize middleware) based on user fields.
217+
218+
```ts title="./index.ts"
219+
export const admin = new AdminForth({
220+
221+
...
222+
223+
auth: {
224+
adminUserAuthorize: [
225+
async ({adminUser, adminforth, extra}) => {
226+
if (adminUser.dbUser.status === 'banned') {
227+
return { allowed: false, error: "User is banned" };
228+
}
229+
return { allowed: true };
230+
}]
231+
}
232+
233+
...
234+
235+
})
236+
237+
```
238+
239+
Now, if a user’s field "status" is changed to "banned", they won’t be able to perform any actions and will be automatically logged out upon accessing the page.

0 commit comments

Comments
 (0)