@joystick.js/ui

accounts.recover_password()

How to use the accounts.recover_password() method in your app.

To start the password recovery process for a user in your app, you can utilize the accounts.recover_password() method.

After a successful call, Joystick will generate a password recovery token and store it on the user.

Example Usage

Example Usage

import joystick, { accounts } from '@joystick.js/ui';

const RecoverPassword = joystick.component({
  events: {
    'submit form': async (event = {}, instance = {}) => {
      accounts.recover_password({
        email_address: event.target.email_address.value,
      }).then(() => {
        location.pathname = '/login';
      }).catch(({ errors }) => {
        // NOTE: All errors are collected into an array of error objects.
        window.alert(errors?.[0]?.message);
      });
    },
  },
  render: ({ props, state, data, each, when, methods }) => {
    return `
      <div class="recover-password">
        <form>
          <label>Email Address</label>
          <input type="email" name="email_address" placeholder="Email Address" />
          <button>Recover Password</button>
        </form>
      </div>
    `;
  },
});

export default RecoverPassword;
Uses Reset Password Template

When sending the email triggered by calling accounts.recover_password(), Joystick will check to see if you have a template defined at email/reset_password.js. Before running this in production, make sure to create this template and match it to your app's branding.

API

accounts.recover_password(options: object) => promise()
email_address string required
The user's email address.