Skip to content
Donald Whalen edited this page Mar 24, 2015 · 6 revisions

auth

Creating a new User for sails-auth is as simple as creating a new Waterline object with the required fields. Just use User.register.

Using local database Authentication

User.register({
    username: 'tjwebb',
    email: '[email protected]'
  })
  .then(function (user) {
    sails.log('created new user', user);
  })
  .catch(function (error) {
    sails.log.error(error);
  });

Using sails-permissions

With sails-permissions, new Users should only be created through the sails.js REST API, e.g.

POST /user
{
  username: 'tjwebb',
  email: '[email protected]',
  password: 'test1234'
}

Or, if using a passport.js provider:

GET /auth/google

This ensures that the User will automatically set its createdBy and owner attributes properly, which are required for proper security when using sails-permissions.

Using passport.js (Google, Facebook, etc) Authentication

Send a request to the specified provider endpoint. e.g. if you're using passport-google for Google OpenID authentication, simply visit

/auth/google

More information on passport.js Providers available here: http://passportjs.org/guide/