@joystick.js/ui

accounts.login()

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

To log an existing user into your app, you can utilize the accounts.login() method. This method returns an object representing the current user.

Example Usage

Example Usage

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

const Login = joystick.component({
  events: {
    'submit form': async (event = {}, instance = {}) => {
      accounts.login({
        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="login">
        <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>Log In</button>
        </form>
      </div>
    `;
  },
});

export default Login;

API

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