a Sails application
- setup your database in
config/connections.js
, for example;
starterMysqlServer: {
adapter: 'sails-mysql',
host: '127.0.0.1',
user: 'root', //optional
password: '', //optional
database: 'sailstarter' //optional
}
- goto
config/models.js
and enabled it;
connection: 'starterMysqlServer',
...
migrate: 'alter'
-
create
isAuthorized.js
inapp/policies
, example isAuthorized.js -
don't forget to create
jwToken.js
inapp/services
, example jwToken.js
- Users model, like this
- and, UsersController, like this
- risk! don't miss it! add this policies in
config/policies.js
:
'UsersController': {
'*': 'isAuthorized',
'create': true, // We dont need authorization here, allowing public access
'login': true // We dont need authorization here, allowing public access
},
- and finally, add this routes in
config/routes.js
:
'POST /users/login': {
controller: 'UsersController',
action: 'login'
},
'POST /users/register': {
controller: 'UsersController',
action: 'create'
}
POST http://baseurl:port/users/login
POST http://baseurl:port/users/register