CWA 2 is a prerelease (2.0.0-alpha), heading for a beta. It runs production sites; configuration can still change between releases, always with upgrade notes. View versions and support
Auth

useCwaAccount, useCwaChangePassword and useCwaChangeEmail

Read the signed-in user's account and change their own password and email, to build an account page of your own.

The admin's My account page (/_cwa/account) is built from these three composables, and you can build an account page of your own from them. Each one works on the signed-in user, so a user can only change their own account with them.

const { account, loading, loadFailed, reload } = useCwaAccount()
const { oldPassword, password, repeatPassword, submit, submitting, fieldErrors, saved } = useCwaChangePassword()
const { newEmail, oldPassword, submit, cancel, pending, submitting, fieldErrors } = useCwaChangeEmail()

None of them takes parameters.

useCwaAccount

It loads the signed-in user from /me when the component mounts.

ReturnTypePurpose
accountRef<CwaUser | undefined>The user as /me returns it, such as username, emailAddress, emailAddressVerified, newEmailAddress and roles
loadingRef<boolean>true while /me is loading
loadFailedRef<boolean>true when /me failed. The user stays signed in
reload() => Promise<void>Load /me again, for a Try again button

useCwaChangePassword

Bind the three fields, then call submit(). It sends oldPassword and plainPassword in a PATCH to the signed-in user (see Authentication › Setting a Password).

ReturnTypePurpose
oldPasswordRef<string>The current password
passwordRef<string>The new password
repeatPasswordRef<string>The new password again
submit() => Promise<boolean>Send the change. true when it saved; the three fields are then emptied
submittingRef<boolean>true while the request runs
fieldErrorsRef<Record<string, string>>Messages by field: oldPassword, password and repeatPassword
savedRef<boolean>true after a change saved, until the next submit()

When password and repeatPassword differ, submit() sends nothing and sets fieldErrors.repeatPassword to "The passwords don't match." The API's 422 violations land on their fields: a wrong current password on oldPassword, and a rule on the new password (see Authentication › Setting a Password) on password. Any other failure shows an error toast, "Your password wasn't changed.", and changes nothing.

useCwaChangeEmail

Bind newEmail and oldPassword, then call submit(). It sends newEmailAddress and oldPassword in a PATCH to the signed-in user. The email doesn't change straight away: the API emails a link to the new address, and the address changes once it's opened (see User Emails › Email Address Change Flow).

ReturnTypePurpose
newEmailRef<string>The new address
oldPasswordRef<string>The current password, which an email change needs
submit() => Promise<boolean>Send the change. true when it saved; both fields are then emptied
cancel() => Promise<boolean>Cancel a pending change by sending newEmailAddress: null, so its link stops working
pendingComputedRef<string | undefined>The address waiting to be confirmed, if any
submittingRef<boolean>true while a request runs
fieldErrorsRef<Record<string, string>>Messages by field: newEmailAddress and oldPassword

A failure other than a 422 shows an error toast, "Your email wasn't changed." (or "The email change wasn't cancelled."). To resend the confirmation for a pending change, call useResendVerifyEmail's resendVerifyEmail(username, 'new').

An Account Page of Your Own

<template>
  <p v-if="loading">Loading…</p>
  <p v-else-if="loadFailed">Your account couldn't be loaded. <button @click="reload">Try again</button></p>
  <form v-else @submit.prevent="submit">
    <p>Signed in as {{ account?.emailAddress }}</p>
    <input v-model="oldPassword" type="password" autocomplete="current-password">
    <span v-if="fieldErrors.oldPassword">{{ fieldErrors.oldPassword }}</span>
    <input v-model="password" type="password" autocomplete="new-password">
    <span v-if="fieldErrors.password">{{ fieldErrors.password }}</span>
    <input v-model="repeatPassword" type="password" autocomplete="new-password">
    <span v-if="fieldErrors.repeatPassword">{{ fieldErrors.repeatPassword }}</span>
    <button :disabled="submitting">Change password</button>
    <p v-if="saved">Your password has been changed.</p>
  </form>
</template>

<script setup lang="ts">
const { account, loading, loadFailed, reload } = useCwaAccount()
const { oldPassword, password, repeatPassword, submit, submitting, fieldErrors, saved } = useCwaChangePassword()
</script>

An account page of your own also needs cwa: { disabled: true } (see Module Setup › Disable CWA Route Fetching) and the cwa-auth middleware, so only a signed-in user reaches it (see Authentication › Protecting Pages).