CWA 2.0 is in alpha: try it, build with it, give feedback. APIs can still change between releases; see Releases.
Auth
useForgotPassword
State and a submit function for a form that requests a password reset email.
useForgotPassword requests a password reset email for a username. The layer's /forgot-password page uses it.
const { credentials, doSubmit, submitting, success, error } = useForgotPassword()
Signature
useForgotPassword()
It takes no parameters.
Return Values
| Return | Type | Purpose |
|---|---|---|
credentials | { username: string } | A reactive() object. Bind the input to credentials.username |
doSubmit | () => Promise<void> | Calls cwa.auth.forgotPassword(), which sends GET /password/reset/request/{username}. After a success, calling it again navigates to /login |
submitting | Ref<boolean> | true while the request runs |
success | Ref<boolean> | true once the email has been requested |
error | Ref<string | undefined> | A message for the visitor; see below |
Error Messages
| Situation | error |
|---|---|
| No username entered | Please enter a username |
404 | Username not found |
429, a reset was requested recently | A reset email was already sent recently. Please check your inbox and spam folder. |
503, the email couldn't be sent | The email couldn't be sent. Please try again. |
400, the API refused to send it | The email couldn't be sent. Please contact the site administrator. The console also logs a warning about the API's user.email_links.allowed_origins |
| Anything else | The API's message, its status text, or Unexpected error |
There's no countdown after a 429, because the API's wait defaults to 24 hours (password_reset.repeat_ttl_seconds). See Throttled and Failed Email Requests.
Example
Authentication → Password Reset shows both steps of a reset.