From 1a666df795bcd67f29f78640b160af8e37dd58d1 Mon Sep 17 00:00:00 2001 From: valentinkolb Date: Wed, 29 May 2024 11:49:27 +0200 Subject: [PATCH] fix(EmailTokenVerifikation): fixed the bug where the verification was working but didn't show it on the frontend --- .../users/modals/EmailTokenVerification.tsx | 7 +++++-- src/lib/pocketbase.tsx | 11 +++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/users/modals/EmailTokenVerification.tsx b/src/components/users/modals/EmailTokenVerification.tsx index 7d2213f..3c5c6a1 100644 --- a/src/components/users/modals/EmailTokenVerification.tsx +++ b/src/components/users/modals/EmailTokenVerification.tsx @@ -6,6 +6,7 @@ import {showErrorNotification, showSuccessNotification} from "@/components/util. import {Alert, Button, Group, Modal, TextInput, Title} from "@mantine/core"; import {IconAt} from "@tabler/icons-react"; import {useLogin} from "@/components/users/modals/hooks.ts"; +import {ClientResponseError} from "pocketbase"; export const EMAIL_TOKEN_KEY = "emailVerificationToken" @@ -32,7 +33,8 @@ export default function EmailTokenVerification() { const verifyTokenMutation = useMutation({ mutationFn: async (token: string) => { - await pb.collection("users").confirmVerification(token) + const res = await pb.collection("users").confirmVerification(token) + console.log({res}) }, onSuccess: () => { showSuccessNotification("E-Mail erfolgreich verifiziert") @@ -41,7 +43,8 @@ export default function EmailTokenVerification() { loginHandler.open() } }, - onError: () => { + onError: (e) => { + if (e instanceof ClientResponseError && e.isAbort) return null showErrorNotification("Fehler beim Verifizieren der E-Mail") } }) diff --git a/src/lib/pocketbase.tsx b/src/lib/pocketbase.tsx index 570ddd9..6987643 100644 --- a/src/lib/pocketbase.tsx +++ b/src/lib/pocketbase.tsx @@ -105,12 +105,19 @@ const PocketData = () => { const refreshUserQuery = useQuery({ queryKey: ["refreshUser"], queryFn: async () => { + // dont refresh if not logged in + if (!pb.authStore.isValid) return null try { const record = await pb.collection(PB_USER_COLLECTION).getOne(pb.authStore.model?.id ?? "", { expand: "memberOf" }) - pb.authStore.save(pb.authStore.token, record) - return record + if (record.verified) { + pb.authStore.save(pb.authStore.token, record) + return record + } else { + pb.authStore.clear() + return null + } } catch (e) { if (e instanceof ClientResponseError && e.status === 401) { pb.authStore.clear()