API Docs for: 0.2.1
Show:

Hook.Auth Class

Module: Hook

Deals with user registration/authentication

Methods

forgotPassword

(
  • data
)
Promise

Send a 'forgot password' confirmation email to target user email address.

Parameters:

  • data Object

Returns:

Promise:

Example:

client.auth.forgotPassword({
  email: "edreyer@doubleleft.com",
  subject: "Project name: Forgot your password?",
  template: "Hi {{name}}, click here to reset your password http://custom-project.com/pass-recovery-path.html?token={{token}}"
}).then(function(data){
  console.log("Email enviado!", data);
}, function(data){
  console.log("User not found: ", data);
});

getToken

() String | Null

Returns:

String | Null:

login

(
  • data
)
Promise

Verify if user is already registered, and log-in if succeed.

Parameters:

  • data Object

Returns:

Promise:

Example:

client.auth.login({email: "edreyer@doubleleft.com", password: "123"}).then(function(data){
  console.log("User found: ", data);
}, function(data){
  console.log("User not found or password invalid.", data);
});

logout

() Hook.Auth

Returns:

Hook.Auth:

this

register

(
  • data
)

Register a user.

Parameters:

  • data Object

Example:

Register with email address

client.auth.register({
  email: "endel@doubleleft.com",
  password: "12345",
  name: "Endel Dreyer"
}).then(function(user) {
  console.log("Registered user: ", user);
});

resetPassword

(
  • data
)
Promise

Reset user password

Parameters:

  • data Object
    • password Object
    • token Object

      [optional]

Returns:

Promise:

Example:

Getting token automatically from query string

client.auth.resetPassword("my-new-password-123").then(function(data){
  console.log("Password reseted! ", data);
}, function(data){
  console.log("Error", data.error);
});

Providing a token manually

client.auth.resetPassword({token: "xxx", password: "my-new-password-123"}).then(function(data){
  console.log("Password reseted! ", data);
}, function(data){
  console.log("Error", data.error);
});

setUserData

(
  • data
)
Hook.Auth

Parameters:

  • data Object

Returns:

Hook.Auth:

this

update

(
  • data
)
Promise

Update current user info.

Parameters:

  • data Object

Returns:

Promise:

Example:

client.auth.update({ score: 100 }).then(function(data){
  console.log("updated successfully: ", data);
}).otherwise(function(data){
  console.log("error: ", data);
});

Properties

currentUser

Object