1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-12-02 17:33:36 +02:00
Files
pocketbase/ui/src/components/records/PageRecordConfirmVerification.svelte

118 lines
3.5 KiB
Svelte
Raw Normal View History

2022-07-07 00:19:05 +03:00
<script>
import FullPage from "@/components/base/FullPage.svelte";
2024-09-29 19:23:19 +03:00
import ApiClient from "@/utils/ApiClient";
import PocketBase, { getTokenPayload, isTokenExpired } from "pocketbase";
2022-07-07 00:19:05 +03:00
export let params;
2024-09-29 19:23:19 +03:00
let successConfirm = false;
let isConfirming = false;
let successResend = false;
let isResending = false;
2022-07-07 00:19:05 +03:00
send();
async function send() {
2024-09-29 19:23:19 +03:00
if (isConfirming) {
return;
}
2022-07-07 00:19:05 +03:00
2024-09-29 19:23:19 +03:00
isConfirming = true;
// init a custom client to avoid interfering with the superuser state
const client = new PocketBase(import.meta.env.PB_BACKEND_URL);
2022-07-07 00:19:05 +03:00
try {
2022-10-30 10:28:14 +02:00
const payload = getTokenPayload(params?.token);
await client.collection(payload.collectionId).confirmVerification(params?.token);
2024-09-29 19:23:19 +03:00
successConfirm = true;
2022-07-07 00:19:05 +03:00
} catch (err) {
2024-09-29 19:23:19 +03:00
successConfirm = false;
2022-07-07 00:19:05 +03:00
}
2024-09-29 19:23:19 +03:00
isConfirming = false;
}
$: canResend = params?.token && isTokenExpired(params.token);
async function resend() {
const payload = getTokenPayload(params?.token);
if (isResending || !payload.collectionId || !payload.email) {
return;
}
isResending = true;
// init a custom client to avoid interfering with the superuser state
const client = new PocketBase(import.meta.env.PB_BACKEND_URL);
try {
const payload = getTokenPayload(params?.token);
await client.collection(payload.collectionId).requestVerification(payload.email);
successResend = true;
} catch (err) {
ApiClient.error(err);
successResend = false;
}
isResending = false;
2022-07-07 00:19:05 +03:00
}
</script>
<FullPage nobranding>
2024-09-29 19:23:19 +03:00
{#if isConfirming}
2022-07-07 00:19:05 +03:00
<div class="txt-center">
<div class="loader loader-lg">
<em>Please wait...</em>
</div>
</div>
2024-09-29 19:23:19 +03:00
{:else if successConfirm}
2022-07-07 00:19:05 +03:00
<div class="alert alert-success">
<div class="icon"><i class="ri-checkbox-circle-line" /></div>
<div class="content txt-bold">
<p>Successfully verified email address.</p>
</div>
</div>
2024-09-29 19:23:19 +03:00
<button type="button" class="btn btn-transparent btn-block" on:click={() => window.close()}>
Close
</button>
{:else if successResend}
<div class="alert alert-success">
<div class="icon"><i class="ri-checkbox-circle-line" /></div>
<div class="content txt-bold">
<p>Please check your email for the new verification link.</p>
</div>
</div>
<button type="button" class="btn btn-transparent btn-block" on:click={() => window.close()}>
2022-07-07 00:19:05 +03:00
Close
</button>
{:else}
<div class="alert alert-danger">
<div class="icon"><i class="ri-error-warning-line" /></div>
<div class="content txt-bold">
<p>Invalid or expired verification token.</p>
</div>
</div>
2024-09-29 19:23:19 +03:00
{#if canResend}
<button
type="button"
class="btn btn-transparent btn-block"
class:btn-loading={isResending}
disabled={isResending}
on:click={resend}
>
<span class="txt">Resend</span>
</button>
{:else}
<button type="button" class="btn btn-transparent btn-block" on:click={() => window.close()}>
Close
</button>
{/if}
2022-07-07 00:19:05 +03:00
{/if}
</FullPage>