seepur/app/Middleware/AdminAuth.js

22 lines
567 B
JavaScript
Raw Normal View History

2020-03-17 22:16:34 +00:00
'use strict'
/** @typedef {import('@adonisjs/framework/src/Request')} Request */
/** @typedef {import('@adonisjs/framework/src/Response')} Response */
/** @typedef {import('@adonisjs/framework/src/View')} View */
class AdminAuth {
/**
* @param {object} ctx
* @param {Request} ctx.request
* @param {Function} next
*/
async handle({request, auth, response}, next) {
// console.log(auth.user);
if (!auth.user.is_admin) response.redirect('/');
// call next to advance the request
else
await next()
}
}
module.exports = AdminAuth