From 94c271d07ecefbfcda8f929ea9a1ebb021258f99 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Fri, 8 Nov 2024 16:23:58 +0100 Subject: [PATCH] redirect to pricing back --- src/lib/components/LoginPopup.svelte | 55 +++++++++++++++------------- src/routes/pricing/+page.server.ts | 6 +-- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/lib/components/LoginPopup.svelte b/src/lib/components/LoginPopup.svelte index c822f7a0..6ed2ea44 100644 --- a/src/lib/components/LoginPopup.svelte +++ b/src/lib/components/LoginPopup.svelte @@ -5,6 +5,7 @@ import toast from "svelte-french-toast"; import Input from "$lib/components/Input.svelte"; import { screenWidth } from "$lib/store"; + import { page } from "$app/stores"; export let form; @@ -17,20 +18,6 @@ return async ({ result, update }) => { switch (result.type) { case "success": - if (form?.notVerified) { - toast.error("Please verify your email first", { - style: "border-radius: 200px; background: #333; color: #fff;", - }); - await update(); - break; - } else form?.notVerified === false; - { - toast.success("Login successfully!", { - style: "border-radius: 200px; background: #333; color: #fff;", - }); - await update(); - break; - } case "redirect": isClicked = true; toast.success("Login successfully!", { @@ -53,17 +40,18 @@ await update(); } - /* - setTimeout(() => { - if (result.type === 'redirect') { - const anchor = document.createElement('a'); - anchor.href = '/'; - anchor.dataset.sveltekitReload = true; - document.body.appendChild(anchor); - anchor.dispatchEvent(new MouseEvent('click')); - } - }, 280); - */ + setTimeout(() => { + if ( + ["redirect", "success"]?.includes(result.type) && + $page?.url?.pathname === "/pricing" + ) { + const anchor = document.createElement("a"); + anchor.href = "/pricing"; + anchor.dataset.sveltekitReload = true; + document.body.appendChild(anchor); + anchor.dispatchEvent(new MouseEvent("click")); + } + }, 280); loading = false; }; @@ -74,6 +62,7 @@ return async ({ result, update }) => { switch (result.type) { case "success": + case "redirect": isClicked = true; toast.success("Registration successfully!", { style: "border-radius: 200px; background: #333; color: #fff;", @@ -94,6 +83,20 @@ default: await update(); } + + setTimeout(() => { + if ( + ["redirect", "success"]?.includes(result.type) && + $page?.url?.pathname === "/pricing" + ) { + const anchor = document.createElement("a"); + anchor.href = "/pricing"; + anchor.dataset.sveltekitReload = true; + document.body.appendChild(anchor); + anchor.dispatchEvent(new MouseEvent("click")); + } + }, 280); + loading = false; }; }; @@ -209,7 +212,7 @@ const output = await response.json(); >
- Signing Up + Signing Up
{/if} diff --git a/src/routes/pricing/+page.server.ts b/src/routes/pricing/+page.server.ts index d3773b8c..525901fb 100644 --- a/src/routes/pricing/+page.server.ts +++ b/src/routes/pricing/+page.server.ts @@ -61,7 +61,7 @@ export const actions = { error(err.status, err.message); } - redirect(302, "/"); + redirect(302, "/pricing"); }, register: async ({ locals, request }) => { @@ -78,7 +78,7 @@ export const actions = { } try { - let newUser = await locals.pb.collection("users").create(formData); + await locals.pb.collection("users").create(formData); /* await locals.pb?.collection('users').update( newUser?.id, { @@ -101,7 +101,7 @@ await locals.pb?.collection('users').update( error(err.status, err.message); } - redirect(303, "/"); + redirect(302, "/pricing"); }, oauth2: async ({ url, locals, request, cookies }) => {