auth

Logs in to an account. On success the account's details are available in user.is, see Logged in user.

Parameter

Description

username

The account's username.

password

The account's password.

callback

Optional function that receives null on success, or an error message.

user.is is cleared as soon as auth() is called, so it's null until the new login succeeds. Only one login can run at a time: calling auth() again before the first finishes returns "User is already authenticating". Without a callback, errors are logged to the console.

Examples

user.auth("alice", "a strong password", async err => {
  if (err) return console.error(err)

  await user.get("profile").put({lastLogin: Date.now()})
})

// Without a callback, check user.is later to see if it succeeded.
user.auth("alice", "a strong password")

To stay logged in after the page reloads, see store() and recall().