Fixed unauthorized /admin error
parent
9b082538c2
commit
3e2180e90f
|
@ -29,7 +29,7 @@ module.exports = {
|
|||
|
||||
// Ensure administrator
|
||||
ensureAdmin: (req,res,next)=>{
|
||||
if (req.user.isAdmin){ return next(); }
|
||||
if (req.isAuthenticated() && req.user.isAdmin){ return next(); }
|
||||
else {
|
||||
let err = new Error("Unauthorized");
|
||||
err.status = 401;
|
||||
|
|
|
@ -131,7 +131,7 @@ const
|
|||
// Production handlers
|
||||
if (env.mode!=='development') {
|
||||
app.use( (err,req,res,next)=>{
|
||||
if (err.status!==404){ console.error(`❌ ${err.stack}`); }
|
||||
if (err.status!==404&&err.status!==401){ console.error(`❌ ${err.stack}`); }
|
||||
if (res.headersSent) { return next(err); }
|
||||
res.status(err.status||500);
|
||||
res.render('error', {
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
{% extends 'templates/base.html' %}
|
||||
{% block title %}{{super()}} | {% if code %}{{code}} {% endif %}Error{% endblock %}
|
||||
{% block title %}{{super()}} | {% if code %}{{code}}{% endif %}{% if message %}: {{message}}{% else %} Error{% endif%}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<section class='container'>
|
||||
{% if message %}<h2>❌️ {{message}}</h2>{% endif %}
|
||||
{% if stack %}<p>{{stack}}</p>{% else %}
|
||||
{% if code == '404' %}<p>This page does not exist. Maybe you followed a dead link here. </p>
|
||||
{% elif code == '401' %}<p>You aren't allowed in here. Shoo. </p>
|
||||
{% else %}<p>Would you please <a href="https://github.com/Tracman-org/Server/issues/new">report this error</a>? </p>{% endif %}
|
||||
{% if code %}<img style="width:100%" src="https://http.cat/{{code}}.jpg">{% endif %}{% endif %}
|
||||
</section>
|
||||
|
|
Loading…
Reference in New Issue