| 1 | "use client"; |
| 2 | |
| 3 | import { useAuth, useRevokeSession |
| 4 | import type { Session |
| 5 | import Bowser from "bowser |
| 6 | import { LogOut, Monitor |
| 7 | import { toast } |
| 8 | import { FromNowHoverCard } |
| 9 | |
| 10 | import { Badge } |
| 11 | import { Button } |
| 12 | import { |
| 13 | Item, |
| 14 | ItemActions, |
| 15 | ItemContent, |
| 16 | ItemDescription, |
| 17 | ItemMedia, |
| 18 | ItemTitle, |
| 19 | } from "@/components/ui/item"; |
| 20 | import { Spinner } |
| 21 | |
| 22 | export type ActiveSessionProps |
| 23 | activeSession: Session |
| 24 | }; |
| 25 | |
| 26 | export function ActiveSession({ |
| 27 | const { authClient, |
| 28 | useAuth(); |
| 29 | const { data: |
| 30 | |
| 31 | const { mutate: |
| 32 | authClient, |
| 33 | { |
| 34 | onSuccess: () => |
| 35 | toast.success(localization |
| 36 | }, |
| 37 | ); |
| 38 | |
| 39 | const isCurrentSession = |
| 40 | const ua = |
| 41 | const isMobile = |
| 42 | ua.platform.type |
| 43 | |
| 44 | return ( |
| 45 | <Item> |
| 46 | <ItemMedia variant=" |
| 47 | {isMobile ? <Smartphone |
| 48 | </ItemMedia> |
| 49 | <ItemContent> |
| 50 | <ItemTitle> |
| 51 | {ua.browser.name |
| 52 | {ua.os.name |
| 53 | </ItemTitle> |
| 54 | {isCurrentSession ? ( |
| 55 | <Badge variant=" |
| 56 | {localization.settings.currentSession |
| 57 | </Badge> |
| 58 | ) : ( |
| 59 | activeSession.createdAt && |
| 60 | <ItemDescription> |
| 61 | <FromNowHoverCard date={ |
| 62 | </ItemDescription> |
| 63 | ) |
| 64 | )} |
| 65 | </ItemContent> |
| 66 | <ItemActions> |
| 67 | <Button |
| 68 | variant="outline" |
| 69 | size="sm" |
| 70 | onClick={() => |
| 71 | isCurrentSession |
| 72 | ? navigate({ |
| 73 | to: `${basePaths. |
| 74 | }) |
| 75 | : revokeSession(activeSession) |
| 76 | } |
| 77 | disabled={isRevoking} |
| 78 | aria-label={ |
| 79 | isCurrentSession |
| 80 | ? localization.auth. |
| 81 | : localization.settings. |
| 82 | } |
| 83 | > |
| 84 | {isRevoking ? <Spinner |
| 85 | |
| 86 | {isCurrentSession |
| 87 | ? localization.auth. |
| 88 | : localization.settings. |
| 89 | </Button> |
| 90 | </ItemActions> |
| 91 | </Item> |
| 92 | ); |
| 93 | } |