1
0
Fork 0
mirror of https://codeberg.org/MarkusThielker/next-ory.git synced 2025-04-19 09:01:18 +00:00
next-ory/authentication/src/components/sessionItem.tsx
2024-11-24 00:06:39 +01:00

53 lines
No EOL
1.7 KiB
TypeScript

'use client';
import React, { useState } from 'react';
import { Session, SessionDevice } from '@ory/client';
import { Card, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { UAParser } from 'ua-parser-js';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
interface SessionItemProps {
session: Session;
showInvalidate: boolean;
invalidateSession: (id: string) => void;
}
export default function SessionItem({ session, showInvalidate, invalidateSession }: SessionItemProps) {
if (!session.devices || session.devices.length < 1) {
return;
}
const [device] = useState<SessionDevice>(session.devices[0]);
const parser = new UAParser(device.user_agent);
const result = parser.getResult();
return (
<Card className="relative w-full">
<CardHeader>
<CardTitle>
{result.os.name}
</CardTitle>
<CardDescription>
{result.browser.name}, version {result.browser.version} <br/>
Signed in since {new Date(session.authenticated_at!!).toLocaleString()}
</CardDescription>
</CardHeader>
{
showInvalidate ?
<Button
className="absolute top-4 right-4"
onClick={() => invalidateSession(session.id)}>
Invalidate
</Button>
:
<Badge
className="absolute top-4 right-4">
This session
</Badge>
}
</Card>
);
}