const jwt = require('jsonwebtoken')
const User = require("../../models").users
const Role = require("../../models").roles

const staff = async (req, res, next) => {
    try {
       if(req.user.second_role == 1){
        
        console.log("req.user",req.user)
        next()

       }else{
        return res.render("login/staff.ejs", {
            error: {
                statusCode: "401",
                success: false,
                message: "Error",
                error: `You are not authorised to have access to staff dashboard`
            },
            success: {
                statusCode: "200",
                success: false,
                message: undefined,
        }
        }) 
       }
      
       
    } catch (e) {
        return res.render("login/staff.ejs", {
            error: {
                statusCode: "401",
                success: false,
                message: "Error",
                error:  e.message
            },
            success: {
                statusCode: "200",
                success: false,
                message: undefined,
        }
        })  
    }

}

module.exports = staff