@joystick.js/ui

accounts.signup()

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

To create a new user for your app, you can utilize the accounts.signup() method. This method returns an object representing the current user.

Example Usage

Example Usage

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

const Signup = joystick.component({
  events: {
    'submit form': async (event = {}, instance = {}) => {
      accounts.signup({
        email_address: event.target.email_address.value,
        password: event.target.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="signup">
        <form>
          <label>Email Address</label>
          <input type="email" name="email_address" placeholder="Email Address" />
          <label>Password</label>
          <input type="password" name="password" placeholder="Password" /> 
          <button>Sign Up</button>
        </form>
      </div>
    `;
  },
});

export default Signup;

API

accounts.signup(options: object) => promise(user: object)
email_address string required
The new user's email address.
username string
The new user's username. Can optionally be used as an alternative to email_address.
password string required
The new user's password.