Initial project structure with sails.js
This commit is contained in:
26
api/policies/is-logged-in.js
Normal file
26
api/policies/is-logged-in.js
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* is-logged-in
|
||||
*
|
||||
* A simple policy that allows any request from an authenticated user.
|
||||
*
|
||||
* For more about how to use policies, see:
|
||||
* https://sailsjs.com/config/policies
|
||||
* https://sailsjs.com/docs/concepts/policies
|
||||
* https://sailsjs.com/docs/concepts/policies/access-control-and-permissions
|
||||
*/
|
||||
module.exports = async function (req, res, proceed) {
|
||||
|
||||
// If `req.me` is set, then we know that this request originated
|
||||
// from a logged-in user. So we can safely proceed to the next policy--
|
||||
// or, if this is the last policy, the relevant action.
|
||||
// > For more about where `req.me` comes from, check out this app's
|
||||
// > custom hook (`api/hooks/custom/index.js`).
|
||||
if (req.me) {
|
||||
return proceed();
|
||||
}
|
||||
|
||||
//--•
|
||||
// Otherwise, this request did not come from a logged-in user.
|
||||
return res.unauthorized();
|
||||
|
||||
};
|
28
api/policies/is-super-admin.js
Normal file
28
api/policies/is-super-admin.js
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* is-super-admin
|
||||
*
|
||||
* A simple policy that blocks requests from non-super-admins.
|
||||
*
|
||||
* For more about how to use policies, see:
|
||||
* https://sailsjs.com/config/policies
|
||||
* https://sailsjs.com/docs/concepts/policies
|
||||
* https://sailsjs.com/docs/concepts/policies/access-control-and-permissions
|
||||
*/
|
||||
module.exports = async function (req, res, proceed) {
|
||||
|
||||
// First, check whether the request comes from a logged-in user.
|
||||
// > For more about where `req.me` comes from, check out this app's
|
||||
// > custom hook (`api/hooks/custom/index.js`).
|
||||
if (!req.me) {
|
||||
return res.unauthorized();
|
||||
}//•
|
||||
|
||||
// Then check that this user is a "super admin".
|
||||
if (!req.me.isSuperAdmin) {
|
||||
return res.forbidden();
|
||||
}//•
|
||||
|
||||
// IWMIH, we've got ourselves a "super admin".
|
||||
return proceed();
|
||||
|
||||
};
|
Reference in New Issue
Block a user