fix: redirection logic

This commit is contained in:
Arman
2024-06-03 12:23:15 +02:00
parent a88d63e836
commit 19fa04e442
+16
View File
@@ -15,6 +15,7 @@
import Consent from '$lib/components/consent.svelte';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { campaigns } from '$lib/stores/campaigns';
onMount(async () => {
// handle sources
@@ -75,6 +76,21 @@
const pathname = $page.url.pathname;
const user = $page.data.account as Models.User<Record<string, string>>;
const code = $page.url.searchParams.get('code');
if (code) {
try {
const couponData = await sdk.forConsole.billing.getCoupon(code);
if (couponData?.campaign && campaigns.has(couponData.campaign)) {
if (user) {
goto(`${base}/console/apply-credit?code=${code}`);
return;
}
}
} catch (error) {
// Do nothing
}
}
if (shouldRedirect(pathname, authenticationRoutes)) {
if (user?.$id) {
if (shouldRedirect(pathname, acceptedAuthenticatedRoutes)) {