use page from app/state and removed div added notifs

This commit is contained in:
Harsh Mahajan
2025-09-26 12:45:38 +05:30
parent e84df2d58f
commit bfdbc38f78
3 changed files with 29 additions and 32 deletions
@@ -5,15 +5,16 @@
import { sdk } from '$lib/stores/sdk';
import { user } from '$lib/stores/user';
import { get } from 'svelte/store';
import { page } from '$app/stores';
import { page } from '$app/state';
import Link from '$lib/elements/link.svelte';
import { Card, Layout, Typography } from '@appwrite.io/pink-svelte';
import { Dependencies } from '$lib/constants';
import { onMount, onDestroy } from 'svelte';
import { base } from '$app/paths';
import { browser } from '$app/environment';
import { addNotification } from '$lib/stores/notifications';
let { show = $bindable(false), email } = $props();
let { show = $bindable(false), email }: { show?: boolean; email?: string } = $props();
let creating = $state(false);
let emailSent = $state(false);
let resendTimer = $state(0);
@@ -27,11 +28,15 @@
goto(`${base}/login`);
}
} catch (error) {
console.error('Logout error:', error);
addNotification({
type: 'error',
title: 'Logout failed',
message: 'Unable to log out. Please try again or refresh the page.'
});
}
}
const cleanUrl = $derived($page.url.origin + $page.url.pathname);
const cleanUrl = $derived(page.url.origin + page.url.pathname);
// Manage resend timer in localStorage
const TIMER_END_KEY = 'email_verification_timer_end';
@@ -94,6 +99,11 @@
emailSent = true;
startResendTimer();
} catch (error) {
addNotification({
type: 'error',
title: 'Failed to send verification email',
message: 'Unable to send verification email. Please try again.'
});
console.error('Failed to send verification email:', error);
} finally {
creating = false;
@@ -101,7 +111,7 @@
}
async function updateEmailVerification() {
const searchParams = $page.url.searchParams;
const searchParams = page.url.searchParams;
const userId = searchParams.get('userId');
const secret = searchParams.get('secret');
@@ -115,6 +125,11 @@
goto(`${base}/`);
} catch (error) {
addNotification({
type: 'error',
title: 'Email verification failed',
message: 'Unable to verify your email. Please try again.'
});
console.error('Failed to verify email:', error);
}
}
+9 -18
View File
@@ -8,9 +8,7 @@
import { onMount } from 'svelte';
import { base } from '$app/paths';
import { Dependencies } from '$lib/constants';
import type { PageData } from './$types';
let { data }: { data: PageData } = $props();
import { page } from '$app/state';
let sideBarIsOpen = writable(false);
let showAccountMenu = writable(false);
@@ -36,28 +34,28 @@
currentProject: project
};
let showVerificationModal = $state(!data.user?.emailVerification);
let showVerificationModal = $state(!page.data.account?.emailVerification);
$effect(() => {
if (data.user?.emailVerification) {
if (page.data.account?.emailVerification) {
checkEmailVerification();
}
});
async function checkEmailVerification() {
if (data.user?.emailVerification) {
if (page.data.account?.emailVerification) {
await goto(`${base}/`);
}
}
onMount(() => {
if (!data.user) {
if (!page.data.account) {
goto(`${base}/login`);
return;
}
// If email is already verified, redirect immediately
if (data.user?.emailVerification) {
if (page.data.account?.emailVerification) {
checkEmailVerification();
return;
}
@@ -89,12 +87,10 @@
{progressCard}
state="open" />
<div class="main-content">
<!-- Main content area -->
</div>
<!-- email verification modal -->
<SendVerificationEmailModal bind:show={showVerificationModal} email={data.user?.email} />
<SendVerificationEmailModal
bind:show={showVerificationModal}
email={page.data.account?.email} />
</div>
<style lang="scss">
@@ -132,11 +128,6 @@
z-index: 1;
}
.main-content {
filter: blur(4px);
opacity: 0.6;
}
/* ensure modal is above everything and not blurred */
:global(.verify-email-page .email-verification-scrim) {
z-index: 9999 !important;
@@ -1,9 +0,0 @@
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ parent }) => {
const { account } = await parent();
return {
user: account
};
};