feat: enhance opportunity detail and sales flow
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<script lang="ts">
|
||||
import { onMount, onDestroy } from "svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
|
||||
const INTERVAL_MS = 60_000; // 60 seconds
|
||||
|
||||
let timer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
async function checkSession() {
|
||||
try {
|
||||
const res = await fetch("/api/auth/check", {
|
||||
credentials: "same-origin",
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
// Session is dead — redirect to login
|
||||
console.warn("Session expired or invalid — redirecting to login.");
|
||||
goto("/login");
|
||||
}
|
||||
} catch (err) {
|
||||
// Network error (API unreachable, etc.) — don't redirect on transient
|
||||
// failures; the next tick will retry.
|
||||
console.warn("Session check failed (network error):", err);
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
// Run the first check immediately, then every 60 s
|
||||
checkSession();
|
||||
timer = setInterval(checkSession, INTERVAL_MS);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
if (timer) {
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user