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

useResetPassword

State and a submit function for the page a password reset email links to.

useResetPassword sets a new password on the page a reset email links to. It reads the username and token from the route params, so use it on a page at /reset-password/[username]/[token]. The layer's page at that path uses it.

const { passwords, resetPassword, submitting, success, error, inputErrors } = useResetPassword()

Signature

useResetPassword()

It takes no parameters.

Return Values

ReturnTypePurpose
passwords{ first: string, second: string }A reactive() object: the new password and its confirmation
resetPassword() => Promise<void>Calls cwa.auth.resetPassword(), which submits the API's password reset form
submittingRef<boolean>true while the request runs
successRef<boolean>true once the password has been changed
errorRef<string | null>A message for the visitor; see below
inputErrorsComputedRef<{ form, password } | undefined>The form's violations after a 422: form for the whole form, password for the new password. Render them next to the inputs

Errors

  • A 404 sets error to "The reset link is invalid or has expired. Please restart the reset password process."
  • A 422 comes back as a form resource. It is stored, and its violations appear in inputErrors; error stays empty.
  • Anything else sets error to the API's message, its status text, or Unexpected error.

Example

Authentication → Password Reset shows both steps of a reset.