// Get the authorization token from the request header
functioncheckToken(req,res,next,sql){
varauth=req.get('Authorization')
if(!auth){
res.status(403).json({error:{code:403,message:"No Authorization header found, please add a Authorization header. If you don't have one, then do nothing lol"}})
}else{
if(auth.includes('Basic ')){
vartoken=auth.replace('Basic ','')
sql.query("SELECT * FROM Auth WHERE token = ?",token,async(err,result)=>{
if(err){
console.error(err)
res.status(503).json({error:{code:503,message:"Error while getting token list for authentificating."}})
}else{
if(result.length<1){
res.status(401).json({error:{code:401,message:"Authorization Token not found."}})
}else{
if(result[0].validate==0){
res.status(403).json({error:{code:403,message:"Your Token is not validated."}})
}else{
console.log('Connexion from '+result[0].description);
next()
}
}
}
});
}else{
res.status(403).json({error:{code:403,message:"Token not found in Authorization header, please set a Token in Authorization header like this: 'Authorization: Basic [token]'."}})