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
| Return | Type | Purpose |
|---|---|---|
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 |
submitting | Ref<boolean> | true while the request runs |
success | Ref<boolean> | true once the password has been changed |
error | Ref<string | null> | A message for the visitor; see below |
inputErrors | ComputedRef<{ 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
404setserrorto "The reset link is invalid or has expired. Please restart the reset password process." - A
422comes back as a form resource. It is stored, and its violations appear ininputErrors;errorstays empty. - Anything else sets
errorto the API's message, its status text, orUnexpected error.
Example
Authentication → Password Reset shows both steps of a reset.