Procházet zdrojové kódy

when expired goto logout

Daniel Bohry před 9 měsíci
rodič
revize
de59a1331a

+ 1 - 1
src/routes/hooks.client.js

@@ -4,7 +4,7 @@ export async function handleFetch({ request, fetch }) {
 	const response = await fetch(request);
 
 	if (response.status === 401) {
-		await goto('/login');
+		await goto('/logout');
 	}
 
 	return response;

+ 5 - 2
src/routes/insights/+page.svelte

@@ -11,12 +11,15 @@
 	let isLoading = true;
 	let currency = 'USD';
 	let total = 0;
-	// Removed chartKey
 
 	onMount(() => {
 		return authentication.subscribe(async (auth) => {
+			if (new Date(auth?.expirationDate) < new Date()) {
+				await goto('/logout');
+			}
+
 			if (!auth || !auth.token) {
-				await goto('/login');
+				await goto('/logout');
 			} else {
 				authToken = auth.token;
 				await fetchPortfolio();

+ 6 - 3
src/routes/portfolio/+page.svelte

@@ -37,8 +37,12 @@
 		}
 
 		return authentication.subscribe(async (auth) => {
+			if (new Date(auth?.expirationDate) < new Date()) {
+				await goto('/logout');
+			}
+
 			if (!auth || !auth.token) {
-				await goto('/login');
+				await goto('/logout');
 			} else {
 				authToken = auth.token;
 				await fetchPortfolio();
@@ -61,7 +65,6 @@
 			} else {
 				const error = await response.json();
 				console.error('Failed to find portfolio info:', error);
-				await goto('/login');
 			}
 		} catch (err) {
 			console.error('Failed to find portfolio info', err);
@@ -244,7 +247,7 @@
 		const country = {
 			BVMF: 'br',
 			FRA: 'de',
-			ETR: 'eu',
+			ETR: 'eu'
 		};
 
 		return country[market] || 'us';