feat: implement primary account identifier and streamline add account flow via direct Steam login

This commit is contained in:
2026-02-21 03:01:33 +01:00
parent f0740997d0
commit 6f66f33a9b
4 changed files with 56 additions and 185 deletions

View File

@@ -502,6 +502,18 @@ electron_1.ipcMain.handle('share-account-with-user', async (event, steamId, targ
} }
throw new Error('Backend not configured'); throw new Error('Backend not configured');
}); });
electron_1.ipcMain.handle('revoke-account-access', async (event, steamId, targetSteamId) => {
initBackend();
if (backend)
return await backend.revokeAccess(steamId, targetSteamId);
throw new Error('Backend not configured');
});
electron_1.ipcMain.handle('revoke-all-account-access', async (event, steamId) => {
initBackend();
if (backend)
return await backend.revokeAllAccess(steamId);
throw new Error('Backend not configured');
});
electron_1.ipcMain.handle('get-community-accounts', async () => { initBackend(); return backend ? await backend.getCommunityAccounts() : []; }); electron_1.ipcMain.handle('get-community-accounts', async () => { initBackend(); return backend ? await backend.getCommunityAccounts() : []; });
electron_1.ipcMain.handle('get-server-users', async () => { initBackend(); return backend ? await backend.getServerUsers() : []; }); electron_1.ipcMain.handle('get-server-users', async () => { initBackend(); return backend ? await backend.getServerUsers() : []; });
electron_1.ipcMain.handle('switch-account', async (event, loginName) => await handleSwitchAccount(loginName)); electron_1.ipcMain.handle('switch-account', async (event, loginName) => await handleSwitchAccount(loginName));

View File

@@ -8,6 +8,8 @@ electron_1.contextBridge.exposeInMainWorld('electronAPI', {
deleteAccount: (id) => electron_1.ipcRenderer.invoke('delete-account', id), deleteAccount: (id) => electron_1.ipcRenderer.invoke('delete-account', id),
switchAccount: (loginName) => electron_1.ipcRenderer.invoke('switch-account', loginName), switchAccount: (loginName) => electron_1.ipcRenderer.invoke('switch-account', loginName),
shareAccountWithUser: (steamId, targetSteamId) => electron_1.ipcRenderer.invoke('share-account-with-user', steamId, targetSteamId), shareAccountWithUser: (steamId, targetSteamId) => electron_1.ipcRenderer.invoke('share-account-with-user', steamId, targetSteamId),
revokeAccountAccess: (steamId, targetSteamId) => electron_1.ipcRenderer.invoke('revoke-account-access', steamId, targetSteamId),
revokeAllAccountAccess: (steamId) => electron_1.ipcRenderer.invoke('revoke-all-account-access', steamId),
openExternal: (url) => electron_1.ipcRenderer.invoke('open-external', url), openExternal: (url) => electron_1.ipcRenderer.invoke('open-external', url),
openSteamLogin: (steamId) => electron_1.ipcRenderer.invoke('open-steam-login', steamId), openSteamLogin: (steamId) => electron_1.ipcRenderer.invoke('open-steam-login', steamId),
// Server Config & Auth // Server Config & Auth

View File

@@ -67,7 +67,8 @@ class BackendService {
gameBans: account.gameBans, gameBans: account.gameBans,
loginName: account.loginName, loginName: account.loginName,
steamLoginSecure: account.steamLoginSecure, steamLoginSecure: account.steamLoginSecure,
loginConfig: account.loginConfig loginConfig: account.loginConfig,
sessionUpdatedAt: account.sessionUpdatedAt
}, { headers: this.headers }); }, { headers: this.headers });
} }
catch (e) { catch (e) {
@@ -100,5 +101,34 @@ class BackendService {
throw new Error(e.response?.data?.message || 'Failed to share account'); throw new Error(e.response?.data?.message || 'Failed to share account');
} }
} }
async revokeAccess(steamId, targetSteamId) {
if (!this.token)
return;
try {
const response = await axios_1.default.delete(`${this.url}/api/sync/${steamId}/share`, {
headers: this.headers,
data: { targetSteamId }
});
return response.data;
}
catch (e) {
console.error(`[Backend] Failed to revoke access for ${steamId} from ${targetSteamId}`);
throw new Error(e.response?.data?.message || 'Failed to revoke access');
}
}
async revokeAllAccess(steamId) {
if (!this.token)
return;
try {
const response = await axios_1.default.delete(`${this.url}/api/sync/${steamId}/share/all`, {
headers: this.headers
});
return response.data;
}
catch (e) {
console.error(`[Backend] Failed to revoke all access for ${steamId}`);
throw new Error(e.response?.data?.message || 'Failed to revoke all access');
}
}
} }
exports.BackendService = BackendService; exports.BackendService = BackendService;

View File

@@ -25,6 +25,7 @@ import ShieldIcon from '@mui/icons-material/Shield';
import GppBadIcon from '@mui/icons-material/GppBad'; import GppBadIcon from '@mui/icons-material/GppBad';
import PeopleIcon from '@mui/icons-material/People'; import PeopleIcon from '@mui/icons-material/People';
import VerifiedUserIcon from '@mui/icons-material/VerifiedUser'; import VerifiedUserIcon from '@mui/icons-material/VerifiedUser';
import WorkspacePremiumIcon from '@mui/icons-material/WorkspacePremium';
import { useAccounts, type Account } from '../hooks/useAccounts'; import { useAccounts, type Account } from '../hooks/useAccounts';
import { useAppTheme } from '../theme/ThemeContext'; import { useAppTheme } from '../theme/ThemeContext';
import type { ThemeType } from '../theme/SteamTheme'; import type { ThemeType } from '../theme/SteamTheme';
@@ -39,47 +40,13 @@ const Dashboard: React.FC = () => {
} = useAccounts(); } = useAccounts();
const [searchTerm, setSearchTerm] = useState(''); const [searchTerm, setSearchTerm] = useState('');
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false);
const [isSettingsOpen, setIsSettingsOpen] = useState(false); const [isSettingsOpen, setIsSettingsOpen] = useState(false);
const [identifier, setIdentifier] = useState('');
const [addTab, setAddTab] = useState(0);
const [communityAccounts, setCommunityAccounts] = useState<any[]>([]);
const [isCommunityLoading, setIsCommunityLoading] = useState(false);
const [serverUrl, setServerUrl] = useState(''); const [serverUrl, setServerUrl] = useState('');
useEffect(() => { useEffect(() => {
if (serverConfig?.url) setServerUrl(serverConfig.url); if (serverConfig?.url) setServerUrl(serverConfig.url);
}, [serverConfig?.url]); }, [serverConfig?.url]);
const loadCommunity = async () => {
setIsCommunityLoading(true);
try {
const data = await getCommunityAccounts();
setCommunityAccounts(Array.isArray(data) ? data : []);
} catch (e) { } finally { setIsCommunityLoading(false); }
};
useEffect(() => {
if (isAddDialogOpen && addTab === 1) loadCommunity();
}, [isAddDialogOpen, addTab]);
const handleAddAccount = async () => {
if (!identifier) return;
try {
await addAccount({ identifier });
setIsAddDialogOpen(false);
setIdentifier('');
} catch (e) { console.error("[Dashboard] Add failed:", e); }
};
const handleAddFromCommunity = async (commAcc: any) => {
try {
await addAccount({ identifier: commAcc.steamId });
setIsAddDialogOpen(false);
} catch (e) { }
};
const saveSettings = async () => { const saveSettings = async () => {
await updateServerConfig({ url: serverUrl }); await updateServerConfig({ url: serverUrl });
alert("Server URL updated!"); alert("Server URL updated!");
@@ -139,7 +106,7 @@ const Dashboard: React.FC = () => {
variant="contained" variant="contained"
color="primary" color="primary"
startIcon={<AddIcon />} startIcon={<AddIcon />}
onClick={() => setIsAddDialogOpen(true)} onClick={() => openSteamLogin('')}
sx={{ height: 32 }} sx={{ height: 32 }}
> >
Add Add
@@ -185,161 +152,13 @@ const Dashboard: React.FC = () => {
{!isLoading && filteredAccounts.length === 0 && ( {!isLoading && filteredAccounts.length === 0 && (
<Box sx={{ width: '100%', mt: 10, textAlign: 'center' }}> <Box sx={{ width: '100%', mt: 10, textAlign: 'center' }}>
<Typography variant="h6" color="textSecondary"> <Typography variant="h6" color="textSecondary">
No accounts tracked. Click "Add Account" to get started! No accounts tracked. Click "Add" to get started!
</Typography> </Typography>
</Box> </Box>
)} )}
</Container> </Container>
{/* Settings Dialog */} {/* Settings Dialog */}
<Dialog open={isSettingsOpen} onClose={() => setIsSettingsOpen(false)} maxWidth="sm" fullWidth>
<DialogTitle sx={{ backgroundColor: 'background.paper', color: 'text.primary' }}>Settings & Customization</DialogTitle>
<DialogContent sx={{ backgroundColor: 'background.paper', pt: 2 }}>
<Typography variant="subtitle2" gutterBottom sx={{ color: 'primary.main', mt: 1 }}>THEME SELECTION</Typography>
<FormControl fullWidth size="small" sx={{ mb: 3 }}>
<InputLabel sx={{ color: 'text.secondary' }}>Active Theme</InputLabel>
<Select
value={currentTheme || 'steam'}
label="Active Theme"
onChange={(e) => setTheme(e.target.value as ThemeType)}
sx={{ bgcolor: 'rgba(0,0,0,0.1)', color: 'text.primary' }}
>
<MenuItem value="steam">Steam Classic</MenuItem>
<MenuItem value="mocha">Catppuccin Mocha</MenuItem>
<MenuItem value="latte">Catppuccin Latte</MenuItem>
<MenuItem value="nord">Nord Arctic</MenuItem>
<MenuItem value="tokyo">Tokyo Night</MenuItem>
</Select>
</FormControl>
<Divider sx={{ my: 2, borderColor: 'divider' }} />
<Typography variant="subtitle2" gutterBottom sx={{ color: 'primary.main' }}>BACKEND CONFIGURATION</Typography>
<TextField
fullWidth
label="Server URL"
value={serverUrl}
onChange={(e) => setServerUrl(e.target.value)}
placeholder="https://ultimate-ban-tracker.narl.io"
margin="dense"
sx={{ mb: 2 }}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<Button variant="contained" size="small" onClick={saveSettings} sx={{ height: 30 }}>Apply</Button>
</InputAdornment>
),
}}
/>
<Divider sx={{ my: 2, borderColor: 'divider' }} />
<Typography variant="subtitle2" gutterBottom sx={{ color: 'primary.main' }}>COMMUNITY AUTHENTICATION</Typography>
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', p: 2, bgcolor: 'rgba(0,0,0,0.1)', borderRadius: 1 }}>
<Box>
<Typography variant="body2" sx={{ fontWeight: 'bold' }}>
{serverConfig?.token ? "Connected to Server" : "Not Authenticated"}
</Typography>
<Typography variant="caption" color="textSecondary">
{serverConfig?.token ? "Your accounts can now be shared with others." : "Login to share and sync with your community."}
</Typography>
</Box>
<Box sx={{ display: 'flex', gap: 1 }}>
{serverConfig?.token && (
<Button
variant="outlined"
color="error"
onClick={() => updateServerConfig({ token: undefined, enabled: false })}
>
Logout
</Button>
)}
<Button
variant="outlined"
color="primary"
onClick={() => loginToServer()}
disabled={!serverUrl}
>
{serverConfig?.token ? "Re-Login" : "Login with Steam"}
</Button>
</Box>
</Box>
<FormControlLabel
control={
<Switch
checked={serverConfig?.enabled || false}
onChange={(e) => updateServerConfig({ enabled: e.target.checked })}
disabled={!serverConfig?.token}
/>
}
label="Enable Community Sync"
sx={{ mt: 2 }}
/>
</DialogContent>
<DialogActions sx={{ backgroundColor: 'background.paper', p: 2 }}>
<Button onClick={() => setIsSettingsOpen(false)} color="inherit" variant="contained">Done</Button>
</DialogActions>
</Dialog>
{/* Add Account Dialog */}
<Dialog open={isAddDialogOpen} onClose={() => setIsAddDialogOpen(false)} maxWidth="sm" fullWidth>
<DialogTitle sx={{ backgroundColor: 'background.paper', color: 'text.primary', p: 0 }}>
<Tabs value={addTab} onChange={(_, v) => setAddTab(v)} variant="fullWidth" textColor="inherit" indicatorColor="primary">
<Tab label="Manual Add" icon={<AddIcon />} iconPosition="start" />
<Tab label="From Community" icon={<PublicIcon />} iconPosition="start" disabled={!serverConfig?.token} />
</Tabs>
</DialogTitle>
<DialogContent sx={{ backgroundColor: 'background.paper', pt: 2, minHeight: 300 }}>
{addTab === 0 ? (
<>
<Typography variant="body2" color="textSecondary" sx={{ mb: 2 }}>
Enter a SteamID64 or Profile URL. You will need to authenticate to enable full tracking and instant login features.
</Typography>
<TextField
fullWidth
autoFocus
placeholder="SteamID64 or Profile URL"
value={identifier}
onChange={(e) => setIdentifier(e.target.value)}
sx={{ '& .MuiOutlinedInput-root': { backgroundColor: 'rgba(0, 0, 0, 0.1)' } }}
/>
</>
) : (
<Box>
{isCommunityLoading ? (
<Box sx={{ display: 'flex', justifyContent: 'center', p: 4 }}><CircularProgress size={32} /></Box>
) : (
<List>
{communityAccounts
.filter(ca => !safeAccounts.find(a => a.steamId === ca.steamId))
.map((ca) => (
<ListItem key={ca.steamId} divider sx={{ borderColor: 'divider' }}>
<Avatar src={ca.avatar} variant="square" sx={{ width: 32, height: 32, mr: 2 }} />
<ListItemText
primary={ca.personaName}
secondary={ca.steamId}
primaryTypographyProps={{ sx: { color: 'text.primary', fontWeight: 'bold' } }}
/>
<ListItemSecondaryAction>
<Button size="small" variant="contained" onClick={() => handleAddFromCommunity(ca)}>Add</Button>
</ListItemSecondaryAction>
</ListItem>
))}
{communityAccounts.length === 0 && <Typography align="center" color="textSecondary" sx={{ p: 4 }}>No shared accounts found on server.</Typography>}
</List>
)}
</Box>
)}
</DialogContent>
<DialogActions sx={{ backgroundColor: 'background.paper', p: 2 }}>
<Button onClick={() => setIsAddDialogOpen(false)} color="inherit">Cancel</Button>
{addTab === 0 && <Button onClick={handleAddAccount} variant="contained" color="success" disabled={!identifier}>Add</Button>}
</DialogActions>
</Dialog>
</Box>
);
};
// --- Sub-Component: AccountRow --- // --- Sub-Component: AccountRow ---
@@ -415,6 +234,9 @@ const AccountRow: React.FC<{
const isBanned = account?.vacBanned || (account?.gameBans && account.gameBans > 0); const isBanned = account?.vacBanned || (account?.gameBans && account.gameBans > 0);
// Primary account check
const isPrimaryAccount = serverConfig?.serverSteamId === account.steamId;
// Refined Shared Logic: // Refined Shared Logic:
// 1. It was shared WITH you (starts with shared_) // 1. It was shared WITH you (starts with shared_)
// 2. OR you are the owner but you have shared it with at least one person // 2. OR you are the owner but you have shared it with at least one person
@@ -427,6 +249,11 @@ const AccountRow: React.FC<{
<TableCell> <TableCell>
<Box sx={{ position: 'relative' }}> <Box sx={{ position: 'relative' }}>
<Avatar src={imgSrc} variant="square" sx={{ width: 32, height: 32, border: '1px solid', borderColor: 'divider' }} /> <Avatar src={imgSrc} variant="square" sx={{ width: 32, height: 32, border: '1px solid', borderColor: 'divider' }} />
{isPrimaryAccount && (
<Tooltip title="Primary Community Account">
<WorkspacePremiumIcon sx={{ position: 'absolute', top: -8, left: -8, fontSize: 18, color: '#FFD700', filter: 'drop-shadow(0 0 2px rgba(0,0,0,0.5))' }} />
</Tooltip>
)}
{showCommunityIcon && ( {showCommunityIcon && (
<Tooltip title={isSharedWithYou ? "Remote Shared Account" : "Actively Shared with Community"}> <Tooltip title={isSharedWithYou ? "Remote Shared Account" : "Actively Shared with Community"}>
<PeopleIcon sx={{ position: 'absolute', bottom: -4, right: -4, fontSize: 14, color: 'primary.main', bgcolor: 'background.default', borderRadius: '50%', border: '1px solid', borderColor: 'divider', p: 0.2 }} /> <PeopleIcon sx={{ position: 'absolute', bottom: -4, right: -4, fontSize: 14, color: 'primary.main', bgcolor: 'background.default', borderRadius: '50%', border: '1px solid', borderColor: 'divider', p: 0.2 }} />