#4 - add support for sharing pages publicly, without login
This commit is contained in:
@@ -16,14 +16,14 @@ class UserRoute extends Middleware {
|
||||
* It should either call the next function in the stack,
|
||||
* or it should handle the response accordingly.
|
||||
*/
|
||||
async test(req, res, next, args = {}){
|
||||
async test(req, res, next, {allow_public_user = false}){
|
||||
const User = this.models.get('auth:User')
|
||||
const user_id = req.form.user_id ? req.form.user_id : req.params.user_id
|
||||
|
||||
if ( !user_id ) return res.status(400).message('Midding user_id.').api({})
|
||||
|
||||
const user = await User.findById(user_id)
|
||||
if ( !user ) return res.status(404).message('Unable to find user with that ID.').api({})
|
||||
if ( !user && !allow_public_user ) return res.status(404).message('Unable to find user with that ID.').api({})
|
||||
|
||||
if ( !req.form ) req.form = {}
|
||||
req.form.user = user
|
||||
|
||||
@@ -5,7 +5,7 @@ class ApiRoute extends Middleware {
|
||||
return [...super.services, 'models']
|
||||
}
|
||||
|
||||
async test(req, res, next, { allow_public = false }) {
|
||||
async test(req, res, next, { allow_public = true }) {
|
||||
// If we have an authenticated session, just continue
|
||||
if ( req.is_auth ) {
|
||||
return next()
|
||||
|
||||
Reference in New Issue
Block a user