2026-01-07 09:31:02 +00:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
|
import { Card } from '../../ui/card';
|
|
|
|
|
import { Button } from '../../ui/button';
|
|
|
|
|
import { Smartphone, Monitor, Clock } from 'lucide-react';
|
2026-01-26 13:12:17 +00:00
|
|
|
import { useToast } from '../../../components/feedback/ToastProvider';
|
2026-01-07 09:31:02 +00:00
|
|
|
import { sessionService, Session } from '../../../services/sessionService';
|
|
|
|
|
import { logger } from '@/utils/logger';
|
|
|
|
|
|
|
|
|
|
export const SessionManagement: React.FC = () => {
|
|
|
|
|
const { addToast } = useToast();
|
|
|
|
|
const [sessions, setSessions] = useState<Session[]>([]);
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-01-13 18:47:57 +00:00
|
|
|
loadSessions();
|
2026-01-07 09:31:02 +00:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const loadSessions = async () => {
|
2026-01-13 18:47:57 +00:00
|
|
|
try {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
const res = await sessionService.getSessions();
|
|
|
|
|
setSessions(res.sessions);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.error('Error loading sessions', {
|
|
|
|
|
error: error instanceof Error ? error.message : String(error),
|
|
|
|
|
stack: error instanceof Error ? error.stack : undefined,
|
|
|
|
|
});
|
|
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
2026-01-07 09:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleRevoke = async (id: string) => {
|
|
|
|
|
try {
|
2026-01-13 18:47:57 +00:00
|
|
|
await sessionService.revokeSession(id);
|
|
|
|
|
setSessions((prev) => prev.filter((s) => s.id !== id));
|
|
|
|
|
addToast('Session revoked successfully', 'success');
|
2026-04-30 21:05:32 +00:00
|
|
|
} catch {
|
2026-01-13 18:47:57 +00:00
|
|
|
addToast('Failed to revoke session', 'error');
|
2026-01-07 09:31:02 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleRevokeAll = async () => {
|
|
|
|
|
try {
|
2026-01-13 18:47:57 +00:00
|
|
|
await sessionService.logoutAll();
|
|
|
|
|
// Ideally reload or clear all except current, but for safety re-fetch
|
|
|
|
|
loadSessions();
|
|
|
|
|
addToast('All other sessions have been logged out', 'success');
|
2026-04-30 21:05:32 +00:00
|
|
|
} catch {
|
2026-01-13 18:47:57 +00:00
|
|
|
addToast('Failed to log out all devices', 'error');
|
2026-01-07 09:31:02 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-13 18:47:57 +00:00
|
|
|
if (loading)
|
|
|
|
|
return (
|
2026-02-07 15:02:52 +00:00
|
|
|
<div className="text-center p-4 text-muted-foreground">Loading sessions...</div>
|
2026-01-13 18:47:57 +00:00
|
|
|
);
|
2026-01-07 09:31:02 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Card variant="default">
|
|
|
|
|
<div className="flex justify-between items-center mb-6">
|
|
|
|
|
<div>
|
2026-02-10 08:43:22 +00:00
|
|
|
<h3 className="text-xl font-bold text-foreground">Active Sessions</h3>
|
2026-02-07 15:02:52 +00:00
|
|
|
<p className="text-sm text-muted-foreground">
|
2026-01-13 18:47:57 +00:00
|
|
|
Manage devices logged into your account.
|
|
|
|
|
</p>
|
2026-01-07 09:31:02 +00:00
|
|
|
</div>
|
2026-01-13 18:47:57 +00:00
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
2026-02-07 15:02:52 +00:00
|
|
|
className="text-destructive hover:bg-destructive/10 border-destructive/30"
|
2026-01-13 18:47:57 +00:00
|
|
|
onClick={handleRevokeAll}
|
|
|
|
|
>
|
2026-01-07 09:31:02 +00:00
|
|
|
Log Out All Other Devices
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="space-y-4">
|
2026-01-13 18:47:57 +00:00
|
|
|
{sessions.map((session) => {
|
|
|
|
|
// Simple heuristics for icon since backend might not provide device type explicitly yet
|
|
|
|
|
const isMobile = session.user_agent.toLowerCase().includes('mobile');
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={session.id}
|
fix: stabilize builds, tests, and lint across all stacks
Complete stabilization pass bringing all 3 stacks to green:
Frontend (apps/web/):
- Fix TypeScript nullability in useSeason.ts, useTimeOfDay.ts hooks
- Disable no-undef in ESLint config (TypeScript handles it; JSX misidentified)
- Rename 306 story imports from @storybook/react to @storybook/react-vite
- Fix conditional hook call in useMediaQuery.ts useIsTablet
- Move useQuery to top of LoginPage.tsx component
- Remove useless try/catch in GearFormModal.tsx
- Fix stale closure in ResetPasswordPage.tsx handleChange
- Make Storybook decorators (withRouter, withQueryClient, withToast, withAudio)
no-ops since global StorybookDecorator already provides these — prevents
nested Router / duplicate provider crashes in vitest-browser
- Fix nested MemoryRouter in 3 page stories (TrackDetail, PlaylistDetail, UserProfile)
- Update i18n initialization in test setup (await init before changeLanguage)
- Update ~30 test assertions from English to French to match i18n translations
- Update test assertions to match SUMI V3 design changes (shadow vs border)
- Fix remaining story type errors (PlayerError, PlaylistBatchActions,
TrackFilters, VirtualizedChatMessages)
Backend (veza-backend-api/):
- Fix response_test.go RespondWithAppError signature (2 args, not 3)
- Fix TestErrorContractAuthEndpoints expected error codes
(ErrCodeUnauthorized vs ErrCodeInvalidCredentials)
- Fix TestTrackHandler_GetTrackLikes_Success missing auth middleware setup
- Fix TestPlaybackAnalyticsService_GetTrackStats k-anonymity threshold
(needs 5 unique users, not 1)
- Replace NOW() PostgreSQL function with time.Now() parameter in marketplace
service for SQLite test compatibility
- Add missing AutoMigrate entries in marketplace_test.go
(ProductImage, ProductPreview, ProductLicense, ProductReview)
Results:
- Frontend TypeCheck: 617 errors -> 0 errors
- Frontend ESLint: 349 errors -> 0 errors
- Frontend Vitest: 196 failing tests -> 1 skipped (3396/3397 passing)
- Backend go vet: 1 error -> 0 errors
- Backend tests: 5 failing -> all 13 packages passing
- Rust: 150/150 tests passing (unchanged)
- Storybook audit: 0 errors across 1244 stories
Triage report: docs/TRIAGE_REPORT.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 14:48:07 +00:00
|
|
|
className="flex flex-col md:flex-row md:items-center justify-between p-4 bg-card rounded-xl shadow-[0_0_8px_rgba(26,26,30,0.05)] transition-colors"
|
2026-01-13 18:47:57 +00:00
|
|
|
>
|
|
|
|
|
<div className="flex items-start gap-4">
|
|
|
|
|
<div
|
2026-02-07 15:02:52 +00:00
|
|
|
className={`p-4 rounded-full ${session.is_current ? 'bg-primary/10 text-primary' : 'bg-muted text-muted-foreground'}`}
|
2026-01-13 18:47:57 +00:00
|
|
|
>
|
|
|
|
|
{isMobile ? (
|
|
|
|
|
<Smartphone className="w-6 h-6" />
|
|
|
|
|
) : (
|
|
|
|
|
<Monitor className="w-6 h-6" />
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<div className="flex items-center gap-2">
|
2026-02-10 08:43:22 +00:00
|
|
|
<h4 className="font-bold text-foreground text-sm">
|
2026-01-13 18:47:57 +00:00
|
|
|
{session.ip_address}
|
|
|
|
|
</h4>
|
|
|
|
|
{session.is_current && (
|
2026-02-08 23:17:14 +00:00
|
|
|
<span className="bg-success/10 text-success text-xs px-2 py-0.5 rounded border border-success/30 font-bold">
|
2026-01-13 18:47:57 +00:00
|
|
|
CURRENT DEVICE
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2026-01-07 09:31:02 +00:00
|
|
|
</div>
|
2026-02-07 15:02:52 +00:00
|
|
|
<p className="text-xs text-muted-foreground mt-1 truncate max-w-xs">
|
2026-01-13 18:47:57 +00:00
|
|
|
{session.user_agent}
|
|
|
|
|
</p>
|
2026-02-07 15:02:52 +00:00
|
|
|
<div className="flex items-center gap-4 mt-2 text-xs text-muted-foreground">
|
2026-01-13 18:47:57 +00:00
|
|
|
<span className="flex items-center gap-1">
|
|
|
|
|
<Clock className="w-3 h-3" /> Active:{' '}
|
|
|
|
|
{new Date(session.last_activity).toLocaleString()}
|
|
|
|
|
</span>
|
2026-01-07 09:31:02 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-01-13 18:47:57 +00:00
|
|
|
|
|
|
|
|
{!session.is_current && (
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
fix: stabilize builds, tests, and lint across all stacks
Complete stabilization pass bringing all 3 stacks to green:
Frontend (apps/web/):
- Fix TypeScript nullability in useSeason.ts, useTimeOfDay.ts hooks
- Disable no-undef in ESLint config (TypeScript handles it; JSX misidentified)
- Rename 306 story imports from @storybook/react to @storybook/react-vite
- Fix conditional hook call in useMediaQuery.ts useIsTablet
- Move useQuery to top of LoginPage.tsx component
- Remove useless try/catch in GearFormModal.tsx
- Fix stale closure in ResetPasswordPage.tsx handleChange
- Make Storybook decorators (withRouter, withQueryClient, withToast, withAudio)
no-ops since global StorybookDecorator already provides these — prevents
nested Router / duplicate provider crashes in vitest-browser
- Fix nested MemoryRouter in 3 page stories (TrackDetail, PlaylistDetail, UserProfile)
- Update i18n initialization in test setup (await init before changeLanguage)
- Update ~30 test assertions from English to French to match i18n translations
- Update test assertions to match SUMI V3 design changes (shadow vs border)
- Fix remaining story type errors (PlayerError, PlaylistBatchActions,
TrackFilters, VirtualizedChatMessages)
Backend (veza-backend-api/):
- Fix response_test.go RespondWithAppError signature (2 args, not 3)
- Fix TestErrorContractAuthEndpoints expected error codes
(ErrCodeUnauthorized vs ErrCodeInvalidCredentials)
- Fix TestTrackHandler_GetTrackLikes_Success missing auth middleware setup
- Fix TestPlaybackAnalyticsService_GetTrackStats k-anonymity threshold
(needs 5 unique users, not 1)
- Replace NOW() PostgreSQL function with time.Now() parameter in marketplace
service for SQLite test compatibility
- Add missing AutoMigrate entries in marketplace_test.go
(ProductImage, ProductPreview, ProductLicense, ProductReview)
Results:
- Frontend TypeCheck: 617 errors -> 0 errors
- Frontend ESLint: 349 errors -> 0 errors
- Frontend Vitest: 196 failing tests -> 1 skipped (3396/3397 passing)
- Backend go vet: 1 error -> 0 errors
- Backend tests: 5 failing -> all 13 packages passing
- Rust: 150/150 tests passing (unchanged)
- Storybook audit: 0 errors across 1244 stories
Triage report: docs/TRIAGE_REPORT.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 14:48:07 +00:00
|
|
|
className="mt-4 md:mt-0 text-muted-foreground hover:text-foreground shadow-[0_0_8px_rgba(26,26,30,0.05)] hover:bg-muted"
|
2026-01-13 18:47:57 +00:00
|
|
|
onClick={() => handleRevoke(session.id)}
|
|
|
|
|
>
|
|
|
|
|
Revoke Access
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2026-01-07 09:31:02 +00:00
|
|
|
})}
|
2026-01-13 18:47:57 +00:00
|
|
|
{sessions.length === 0 && (
|
2026-02-08 22:15:53 +00:00
|
|
|
<p className="text-center text-muted-foreground text-sm py-8">No active sessions found.</p>
|
2026-01-13 18:47:57 +00:00
|
|
|
)}
|
2026-01-07 09:31:02 +00:00
|
|
|
</div>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
};
|