fix: correct last-sync date and logout redirect issues
- Fix admin users last-sync showing 1970 instead of actual sync date - Changed from MAX(qsos.createdAt) to MAX(syncJobs.completedAt) - Added timestamp conversion (seconds to milliseconds) for proper Date serialization - Fix logout redirect not working from admin dashboard - Changed from goto() to window.location.href for hard redirect - Ensures proper navigation after auth state changes Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -127,7 +127,12 @@ export async function getUserStats() {
|
|||||||
lotwConfirmed: sql`CAST(SUM(CASE WHEN ${qsos.lotwQslRstatus} = 'Y' THEN 1 ELSE 0 END) AS INTEGER)`,
|
lotwConfirmed: sql`CAST(SUM(CASE WHEN ${qsos.lotwQslRstatus} = 'Y' THEN 1 ELSE 0 END) AS INTEGER)`,
|
||||||
dclConfirmed: sql`CAST(SUM(CASE WHEN ${qsos.dclQslRstatus} = 'Y' THEN 1 ELSE 0 END) AS INTEGER)`,
|
dclConfirmed: sql`CAST(SUM(CASE WHEN ${qsos.dclQslRstatus} = 'Y' THEN 1 ELSE 0 END) AS INTEGER)`,
|
||||||
totalConfirmed: sql`CAST(SUM(CASE WHEN ${qsos.lotwQslRstatus} = 'Y' OR ${qsos.dclQslRstatus} = 'Y' THEN 1 ELSE 0 END) AS INTEGER)`,
|
totalConfirmed: sql`CAST(SUM(CASE WHEN ${qsos.lotwQslRstatus} = 'Y' OR ${qsos.dclQslRstatus} = 'Y' THEN 1 ELSE 0 END) AS INTEGER)`,
|
||||||
lastSync: sql`MAX(${qsos.createdAt})`,
|
lastSync: sql`(
|
||||||
|
SELECT MAX(${syncJobs.completedAt})
|
||||||
|
FROM ${syncJobs}
|
||||||
|
WHERE ${syncJobs.userId} = ${users.id}
|
||||||
|
AND ${syncJobs.status} = 'completed'
|
||||||
|
)`.mapWith(Number),
|
||||||
createdAt: users.createdAt,
|
createdAt: users.createdAt,
|
||||||
})
|
})
|
||||||
.from(users)
|
.from(users)
|
||||||
@@ -135,7 +140,11 @@ export async function getUserStats() {
|
|||||||
.groupBy(users.id)
|
.groupBy(users.id)
|
||||||
.orderBy(sql`COUNT(${qsos.id}) DESC`);
|
.orderBy(sql`COUNT(${qsos.id}) DESC`);
|
||||||
|
|
||||||
return stats;
|
// Convert lastSync timestamps (seconds) to Date objects for JSON serialization
|
||||||
|
return stats.map(stat => ({
|
||||||
|
...stat,
|
||||||
|
lastSync: stat.lastSync ? new Date(stat.lastSync * 1000) : null,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,7 +5,11 @@
|
|||||||
|
|
||||||
function handleLogout() {
|
function handleLogout() {
|
||||||
auth.logout();
|
auth.logout();
|
||||||
goto('/auth/login');
|
// Use hard redirect to ensure proper navigation after logout
|
||||||
|
// goto() may not work properly due to SvelteKit client-side routing
|
||||||
|
if (browser) {
|
||||||
|
window.location.href = '/auth/login';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
import { browser } from '$app/environment';
|
||||||
import { authAPI } from '$lib/api.js';
|
import { authAPI } from '$lib/api.js';
|
||||||
import { auth } from '$lib/stores.js';
|
import { auth } from '$lib/stores.js';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
@@ -93,7 +94,10 @@
|
|||||||
|
|
||||||
function handleLogout() {
|
function handleLogout() {
|
||||||
auth.logout();
|
auth.logout();
|
||||||
goto('/auth/login');
|
// Use hard redirect to ensure proper navigation after logout
|
||||||
|
if (browser) {
|
||||||
|
window.location.href = '/auth/login';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user