seepur/app/Middleware/AdminAuth.js
2020-03-17 18:16:34 -04:00

21 lines
567 B
JavaScript

'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