-
Notifications
You must be signed in to change notification settings - Fork 141
Creating Users
Donald Whalen edited this page Mar 24, 2015
·
6 revisions
Creating a new User for sails-auth is as simple as creating a new Waterline object with the required fields. Just use User.register
.
User.register({
username: 'tjwebb',
email: '[email protected]'
})
.then(function (user) {
sails.log('created new user', user);
})
.catch(function (error) {
sails.log.error(error);
});
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.
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/