# Account recovery

Source: https://developers.swell.is/frontend-api/account-recovery

**Swell.js:**

Methods to recover a customer's account login credentials by sending them a password reset email.

#### Send a password reset email

Use the `recover` method to send an email to the customer with a link to reset their password. If the email address provided doesn't exist in the system, no email will be sent.

*Returns a value indicating success.*

**Send a password reset email**

**swell.js**

```javascript
await swell.account.recover({
  email: 'julia@example.com'
})
```

To customize the password reset URL sent to the customer in an email, pass the optional parameter `reset_url`, including a placeholder for the password reset key: `{reset_key}`. Swell will automatically generate and substitute the password reset key in the URL before sending an email.

**Customize reset password URL**

**swell.js**

```javascript
await swell.account.recover({
  email: 'julia@example.com',
  reset_url: 'https://example.com/password-reset?key={reset_key}'
})
```

> **Note:** Password reset requests automatically expire after 24 hours.

#### Reset an account password

Use to set the customer's new password. This requires the `reset_key` from the recovery email (see above). The password recovery email should link to your storefront with `reset_key` as a URL parameter that you can pass to this method.

**Reset an account password**

**swell.js**

```javascript
await swell.account.recover({
  password: 'thenewpassword',
  reset_key: 'e42e66fc7e3f00e9e179w20ad1841146'
})
```

**GraphQL:**

Methods to recover a customer's account login credentials by sending them a password reset email.

### Send a password reset email

Send a customized password reset URL to the customer to reset their password. Swell will automatically generate and substitute the password reset key in the URL before sending an email. If the email address provided doesn't exist in the system, no email will be sent.

Returns a value indicating success. The parameters for the `sendAccountRecovery` mutation are `email` (required) and `passwordResetUrl` (required).

**Send a password reset URL**

**GraphQL**

```graphql
mutation sendAccountRecovery {
  sendAccountRecovery(
    email: "ancotar@fortcaractacus.net"
    passwordResetUrl: "https://example.com/password-reset?key={reset_key}"
  ) {
    success
  }
}
```

> **Note:** Password reset requests automatically expire after 24 hours.

### Reset an account password

Set up a new password for the customer. This requires the `reset_key` from the recovery email (see above). The password recovery email should link to your storefront with `reset_key` as a URL parameter that you can pass to this method.

Returns a value indicating success. The parameters for the `recoverAccount` mutation are `password` (required) and `passwordResetKey` (required).

**Reset an account password**

**GraphQL**

```graphql
mutation {
  recoverAccount(
    password: "thenewpassword"
    passwordResetKey: "e42e66fc7e3f00e9e179w20ad1841146"
  ) {
    success
  }
}
```
