|
| 1 | +<template> |
| 2 | + <div |
| 3 | + class="bg-zinc-100 grid grid-flow-col justify-items-center items-center min-h-screen py-10" |
| 4 | + > |
| 5 | + <div class="w-11/12 md:w-3/4"> |
| 6 | + <img |
| 7 | + src="@renderer/libretexts_logo.png" |
| 8 | + alt="LibreTexts" |
| 9 | + class="max-w-xs my-0 mx-auto" |
| 10 | + /> |
| 11 | + <div |
| 12 | + class="bg-white p-6 mt-6 shadow-md shadow-gray-400 rounded-md overflow-hidden" |
| 13 | + > |
| 14 | + <div aria-live="polite" :aria-busy="loading"> |
| 15 | + <!-- Loading State --> |
| 16 | + <template v-if="loading"> |
| 17 | + <h1 class="text-center text-3xl font-medium"> |
| 18 | + {{ $t("email_verification.header") }} |
| 19 | + </h1> |
| 20 | + <div class="flex items-center justify-center mt-6"> |
| 21 | + <LoadingIndicator /> |
| 22 | + <span class="ml-2">{{ $t("email_verification.loading") }}</span> |
| 23 | + </div> |
| 24 | + <p class="text-xs text-center text-gray-500 mt-4"> |
| 25 | + {{ $t("email_verification.verify_thanks") }} |
| 26 | + </p> |
| 27 | + </template> |
| 28 | + |
| 29 | + <!-- Success State --> |
| 30 | + <template v-else-if="success"> |
| 31 | + <h1 class="text-center text-3xl font-medium"> |
| 32 | + {{ $t("email_verification.success_header") }} |
| 33 | + </h1> |
| 34 | + <p class="text-center text-gray-700 mt-4"> |
| 35 | + {{ $t("email_verification.success_tagline") }} |
| 36 | + </p> |
| 37 | + <a |
| 38 | + href="/signin" |
| 39 | + class="inline-flex items-center justify-center h-10 bg-primary p-2 mt-6 rounded-md text-white w-full font-medium hover:bg-sky-700 hover:shadow" |
| 40 | + > |
| 41 | + <span>{{ $t("email_verification.continue_to_signin") }}</span> |
| 42 | + <FontAwesomeIcon |
| 43 | + icon="fa-solid fa-circle-arrow-right" |
| 44 | + class="ml-2" |
| 45 | + /> |
| 46 | + </a> |
| 47 | + </template> |
| 48 | + |
| 49 | + <!-- Invalid/Expired Token State --> |
| 50 | + <template v-else> |
| 51 | + <h1 class="text-center text-3xl font-medium"> |
| 52 | + {{ $t("email_verification.error_header") }} |
| 53 | + </h1> |
| 54 | + <p class="text-center text-gray-700 mt-4" v-if="showResendOption"> |
| 55 | + {{ $t("email_verification.error_expired") }} |
| 56 | + </p> |
| 57 | + <p class="text-center text-gray-700 mt-4" v-else> |
| 58 | + {{ $t("email_verification.error_invalid") }} |
| 59 | + </p> |
| 60 | + <p class="text-center text-gray-700 mt-4" v-if="didResend"> |
| 61 | + {{ $t("email_verification.resend_success") }} |
| 62 | + </p> |
| 63 | + <ThemedButton |
| 64 | + v-if="showResendOption && !didResend" |
| 65 | + icon="IconCircleArrowRight" |
| 66 | + @click="resendVerificationEmail" |
| 67 | + class="mt-6 w-full justify-center" |
| 68 | + > |
| 69 | + {{ $t("email_verification.resend_verification") }} |
| 70 | + </ThemedButton> |
| 71 | + </template> |
| 72 | + |
| 73 | + <!-- Error Message --> |
| 74 | + <p |
| 75 | + class="text-center text-red-600 text-sm mt-4 font-bold" |
| 76 | + v-if="error" |
| 77 | + > |
| 78 | + {{ error }} |
| 79 | + </p> |
| 80 | + </div> |
| 81 | + </div> |
| 82 | + </div> |
| 83 | + </div> |
| 84 | +</template> |
| 85 | + |
| 86 | +<script lang="ts" setup> |
| 87 | +import { ref, onMounted } from "vue"; |
| 88 | +import { useAxios } from "@renderer/useAxios"; |
| 89 | +import { usePageProps } from "@renderer/usePageProps"; |
| 90 | +import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome"; |
| 91 | +import LoadingIndicator from "@components/LoadingIndicator.vue"; |
| 92 | +import ThemedButton from "../../components/ThemedButton.vue"; |
| 93 | +
|
| 94 | +const props = usePageProps<{ |
| 95 | + token: string; |
| 96 | +}>(); |
| 97 | +const axios = useAxios(); |
| 98 | +
|
| 99 | +const success = ref(false); |
| 100 | +const loading = ref(true); |
| 101 | +const error = ref<string | null>(null); |
| 102 | +const resendUUID = ref<string | null>(null); |
| 103 | +const showResendOption = ref(false); |
| 104 | +const didResend = ref(false); |
| 105 | +
|
| 106 | +async function submitToken() { |
| 107 | + try { |
| 108 | + loading.value = true; |
| 109 | +
|
| 110 | + const result = await axios.post("/auth/verify-email-token", { |
| 111 | + token: props.token, |
| 112 | + }); |
| 113 | +
|
| 114 | + success.value = result.data.success === true; |
| 115 | + resendUUID.value = result.data.data?.uuid || null; |
| 116 | +
|
| 117 | + // Can only resend if the token expired so we got the UUID back |
| 118 | + // If it was an invalid token, we won't get a UUID |
| 119 | + if (!success.value && resendUUID.value) { |
| 120 | + showResendOption.value = true; |
| 121 | + } |
| 122 | + } catch (e: any) { |
| 123 | + console.error(e); |
| 124 | + success.value = false; |
| 125 | + if (e?.code !== "ERR_BAD_REQUEST") { |
| 126 | + error.value = "An error occurred while verifying your email."; |
| 127 | + } |
| 128 | + } finally { |
| 129 | + loading.value = false; |
| 130 | + } |
| 131 | +} |
| 132 | +
|
| 133 | +async function resendVerificationEmail() { |
| 134 | + try { |
| 135 | + if (!resendUUID.value) return; |
| 136 | +
|
| 137 | + loading.value = true; |
| 138 | +
|
| 139 | + await axios.post("/auth/resend-verification-email", { |
| 140 | + uuid: resendUUID.value, |
| 141 | + }); |
| 142 | +
|
| 143 | + didResend.value = true; |
| 144 | + } catch (e) { |
| 145 | + console.error("Failed to resend verification email:", e); |
| 146 | + error.value = |
| 147 | + "An error occurred while resending the verification email. Please contact our Support Center."; |
| 148 | + } finally { |
| 149 | + loading.value = false; |
| 150 | + } |
| 151 | +} |
| 152 | +
|
| 153 | +// Automatically submit token when component mounts |
| 154 | +onMounted(() => { |
| 155 | + if (props.token) { |
| 156 | + submitToken(); |
| 157 | + } else { |
| 158 | + // No token provided, show error state |
| 159 | + loading.value = false; |
| 160 | + success.value = false; |
| 161 | + } |
| 162 | +}); |
| 163 | +</script> |
0 commit comments