CWA 2.0 is in alpha: try it, build with it, give feedback. APIs can still change between releases; see Releases.
Auth

useVerifyEmail

Verify an email address, or confirm a change of email address, from the link in an email.

useVerifyEmail completes the link in a verification email. verifyEmail() verifies a new account's address, and confirmEmail() confirms a change of address. Both read their values from the route params. The layer's /verify-email/[username]/[token] and /confirm-new-email/[username]/[newEmail]/[token] pages call them on mount.

const { verifyEmail, submitting, success, error } = useVerifyEmail()
onMounted(() => verifyEmail())

Signature

useVerifyEmail()

It takes no parameters.

Return Values

ReturnTypePurpose
verifyEmail() => Promise<void>Reads username and token from the route params and calls cwa.auth.verifyEmail()
confirmEmail() => Promise<void>Reads username, newEmail and token and calls cwa.auth.confirmEmail()
submittingRef<boolean>true while the request runs
successRef<boolean>true once the address is verified or confirmed
errorRef<string | undefined>A message for the visitor; see below
getStringFromParam(name: string) => stringReads one route param as a string, the first value if it is repeated, or ''

Use verifyEmail() on /verify-email/[username]/[token] and confirmEmail() on /confirm-new-email/[username]/[newEmail]/[token]. Call only the one that matches the page.

Errors

  • A missing route param sets error to "No username specified", "No token specified" or "No new email specified", and sends no request.
  • A 404 sets it to "Request expired or has already been used."
  • Anything else sets it to the API's message, its status text, or Unexpected error.

Example

<!-- app/app/pages/verify-email/[username]/[token].vue -->
<script setup lang="ts">
definePageMeta({ cwa: { disabled: true } })
const { verifyEmail, submitting, success, error } = useVerifyEmail()
onMounted(() => verifyEmail())
</script>

<template>
  <p v-if="submitting">Verifying…</p>
  <p v-else-if="success">Your email address is verified.</p>
  <p v-else-if="error">{{ error }}</p>
</template>