Skip to content

Commit be7e61c

Browse files
committed
docs: update docs for user sessions plugin
1 parent c9794b5 commit be7e61c

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎documentation/docs/tutorial/09-Plugins/31-user-sessions.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ The callback is called on every such request, so removing a role takes effect im
6262
When the option is not set, the block is not added to the show page at all, and the endpoints
6363
refuse to touch sessions of anybody but the caller.
6464

65+
## Hiding IP addresses
66+
67+
By default everybody who sees a session sees its IP. When many people share one account, e.g. on a public
68+
demo, they would see IPs of each other. Pass `canSeeIps` to show IPs only to some users:
69+
70+
```ts title="./index.ts"
71+
new UserSessionsPlugin({
72+
keyValueAdapter,
73+
canSeeIps: async (adminUser) => adminUser.dbUser.role === 'superadmin',
74+
})
75+
```
76+
77+
For other users the IP column shows a masked value, own sessions included. Hidden IPs are not sent to the
78+
browser at all, so they can't be read from the network tab either.
79+
80+
The callback covers the "Active sessions" page and the block on the show page of a user. IPs in the
81+
[login history](#login-history) are columns of your own resource, restrict them there, e.g. with
82+
`allowedActions`. The [revoke page](#revoke-page) shows the IP to whoever has the link from `onNewLogin`.
83+
6584
## Client IP and country
6685

6786
IP is taken from [`adminforth.auth.getClientIp`](/docs/tutorial/Customization/security#trusting-client-ip-addresses),
@@ -320,6 +339,7 @@ export default {
320339
| `countryHeader` | `CF-IPCountry` | Header with two-letter country code set by your CDN, empty string disables it |
321340
| `resolveCountry` | — | Called when the header did not tell the country |
322341
| `canManageOtherUsersSessions` | — | `(adminUser) => Promise<boolean>`, decides who may see and revoke sessions of other users |
342+
| `canSeeIps` | — | `(adminUser) => Promise<boolean>`, decides who sees IPs of sessions, see [Hiding IP addresses](#hiding-ip-addresses) |
323343
| `lastUsedThrottleSeconds` | `60` | How often `last_used_at` is refreshed. Every refresh is one write to the adapter |
324344
| `onNewLogin` | — | `({ pk, username, session, reasons, revokePath }) => Promise<void>`, called after a sign-in from a new device or country, see [Notifying about sign-ins from new devices](#notifying-about-sign-ins-from-new-devices) |
325345
| `loginHistory.resourceId` | — | Resource where sign-ins and failed attempts are stored, see [Login history](#login-history) |

0 commit comments

Comments
 (0)