shadcn.io is not affiliated with official shadcn/ui
Active Sessions Account Block for React
The open sessions of an account with how each one signed in, when it started, was last active and ends, an idle filter, a two-step sign-out per row and one button that signs out the rest.
Installation
Overview
Let people see and end the places they are signed in, with this active sessions panel for React with Base UI. A hairline frame with a plus mark on each corner holds a ruled list with a row per session: its browser and system, the place and a documentation address in mono, how it signed in (password and code, a passkey or Google, with a small tile), when it started, when it was last active and the day it ends, worked out from its start. This session comes first with a badge and no sign-out. A Native Select limits the list to sessions idle for 30 or 7 days. Each row signs out in two steps in place, Sign out and then Confirm or Cancel, with Escape cancelling. The header's Shine Button is the only colored control: it signs out every other session, or every idle one while the list is limited, after an Alert Dialog names which ones end. A line at the foot says what happened and Undo brings the last sessions back; when none is left an Empty state fills the space and the panel keeps its height. It's built from Alert Dialog, Native Select, Badge, Empty, Button, Shine Button and Guides, with a CSS entrance only. For the security page of any app that keeps people signed in.
FAQ
How do I fill it with the real sessions?
Edit SESSIONS. Each has an id, the browser as one phrase ("Chrome on macOS"), the city, an ip, a kind that picks the icon (desktop, laptop, phone or tablet), the method it signed in with, ISO started and active days and a current flag for the one the person is using. The end day isn't stored: it is the start plus LIFETIME days, so change that constant to your session length. Every date, the idle filter and "in 8 days" are worked out from the one AS_OF constant, never the clock, so replace it with today's date (or the server's) when you wire it up.
What stays local, and how do I make signing out real?
Everything: signing out removes the row from this page's state and says "ended in this demo", and Undo puts it back, which a real server can't do. To make it real, call your sign-out endpoint in end, remove the rows only when it answers and show a failure in the same status line; call a bulk endpoint in confirmMany for the header button. The address and place are typed with documentation addresses; use your own geolocation, and say it is approximate.
How does the sign-out confirmation work?
Pressing Sign out swaps that button, in place, for Confirm and Cancel, and focus moves to Confirm. Cancel is where Sign out was, so a double click can't confirm by accident. Escape cancels while focus is inside the panel and returns focus to Sign out; confirming moves focus to the next row's Sign out, or to Undo when no row is left. The status line says which session is being asked about. The header button asks in a real alert dialog instead, because it ends several sessions: focus starts on Cancel, Escape closes it and focus returns to the button.
What does the idle filter do?
It limits the list to the sessions that have been idle for at least 30 or 7 days, as of the AS_OF day, and the header button follows it: "Sign out 3 inactive sessions" instead of "Sign out 4 other sessions". This session always stays in the list because it can't be signed out. When nothing matches, a message in the list's own space offers "Show all sessions". The list sits over an unseen copy of the full list, so filtering, signing out and the empty state never change the panel's height.
How does it look on a phone?
Each session is a card: its tile, browser and place first, then its four facts two by two with their names visible, then Sign out at the foot. The foot with the status line and Undo stays pinned to the bottom of the screen while you scroll, so the result of a sign-out is always in view; from the medium breakpoint it is simply the last band. From the large breakpoint the facts become columns under their own heads.
Is it accessible?
The sessions are a real list; each fact has its name read out ("Ends on, 22 Oct") even where a column head shows it instead. Sign out, Confirm and Cancel are named for the session ("Sign out Safari on iOS, Lisbon, Portugal"), how it signed in is written out and never only a tile, and the badge says "This session". The status line is a polite live region present from the start. The addresses read start to end in any language and the dates keep their order in a right-to-left page.
Related
- Pro
Session History Account
Sessions and devicesThe last seven days of sessions as a swimlane: a lane per device, each session a bar placed by its start and length, revoked ones ending in a cut mark, and a popover with the id, length, address and how it ended.
- Pro
Devices Account
Sessions and devicesThe devices that have signed in to an account as hairline tiles grouped by type, each with its browsers, sessions, place, address and a menu to rename or remove it, and one button to remove every other device.
- Pro
Sign-in History Account
Sessions and devicesEvery sign-in attempt in the last 14 days in a sortable, searchable table with failed attempts marked by an icon and a reason, rows that open to the user agent and steps, pages of 5 or 10 and four derived figures.
- Pro
Trusted Devices Account
Sessions and devicesAn account's trusted devices as a table of devices against two switches, one to skip the sign-in code and one to skip the password prompt, with a sentence on what each device's choice means and a meter against the limit.
- Pro
Device Management Dialog
Side sheetsA family notes app's account page with a side sheet of signed-in devices shown open: this device pinned first, Sign out that asks inside the same row, and one button that signs out of all the others the same way.
- Pro
Session Policy Settings
Sign-in and securityA session policy settings panel that leads with the sentence the settings amount to, two sliders with stops for the idle timeout and the longest session that hold each other to one rule, a device limit and an end-all-sessions dialog.