@joystick.js/ui

accounts.reset_password()

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

To reset the password for a user in your app, you can utilize the accounts.reset_password() method.

After a successful call, Joystick will automatically create a new session for the user and log them in (you will be responsible for navigating the user afterward).

Example Usage

Example Usage

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

const ResetPassword = joystick.component({
  events: {
    'submit form': async (event = {}, instance = {}) => {
      accounts.reset_password({
        // NOTE: Assumes that the reset token generated by Joystick is stored in a URL
        // parameter called :token in the route for your Reset Password page.
        token: instance?.url?.params?.token,
        password: event.target.new_password.value,
      }).then(() => {
        location.pathname = '/dashboard';
      }).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="reset-password">
        <form>
          <label>New Password</label>
          <input type="password" name="new_password" placeholder="New Password" />
          <label>Repeat New Password</label>
          <input type="password" name="repeat_new_password" placeholder="Repeat New Password" />
          <button>Reset Password</button>
        </form>
      </div>
    `;
  },
});

export default ResetPassword;

API

accounts.reset_password(options: object) => promise()
token string required
The user's password reset token generated by Joystick.
password string required
The user's new password.