|
| 1 | +import { AdminForthDataTypes, AdminForthSortDirections } from 'adminforth'; |
| 2 | +import type { AdminForthResourceInput } from 'adminforth'; |
| 3 | +import { randomUUID } from 'crypto'; |
| 4 | +import AutoRemovePlugin from '../../plugins/adminforth-auto-remove/index.js'; |
| 5 | + |
| 6 | +export default { |
| 7 | + dataSource: 'sqlite', |
| 8 | + table: 'login_history', |
| 9 | + resourceId: 'login_history', |
| 10 | + label: 'Login History', |
| 11 | + columns: [ |
| 12 | + { name: 'id', primaryKey: true, fillOnCreate: () => randomUUID(), showIn: { all: false } }, |
| 13 | + { name: 'created_at', type: AdminForthDataTypes.DATETIME }, |
| 14 | + { name: 'user_id', foreignResource: { resourceId: 'adminuser' } }, |
| 15 | + { name: 'success', type: AdminForthDataTypes.BOOLEAN }, |
| 16 | + { name: 'attempts', type: AdminForthDataTypes.INTEGER }, |
| 17 | + { name: 'ip', required: false }, |
| 18 | + { name: 'country', required: false }, |
| 19 | + { name: 'user_agent', required: false, showIn: { list: false } }, |
| 20 | + // substring search finds failed attempts by an IP inside the JSON |
| 21 | + { name: 'ips', type: AdminForthDataTypes.JSON, required: false, filterOptions: { substringSearch: true } }, |
| 22 | + ], |
| 23 | + options: { |
| 24 | + allowedActions: { create: false, edit: false, delete: false }, |
| 25 | + defaultSort: { columnName: 'created_at', direction: AdminForthSortDirections.desc }, |
| 26 | + }, |
| 27 | + plugins: [ |
| 28 | + new AutoRemovePlugin({ |
| 29 | + createdAtField: 'created_at', |
| 30 | + mode: 'time-based', |
| 31 | + deleteOlderThan: '3mo', |
| 32 | + interval: '1d', |
| 33 | + }), |
| 34 | + ], |
| 35 | +} as AdminForthResourceInput; |
0 commit comments