Fix admin-clinics auth and JWT usage
This commit is contained in:
@@ -15,10 +15,10 @@ function authenticateToken(req, res, next) {
|
||||
|
||||
// Se não tem token, verifica se está tentando acessar uma página
|
||||
if (!token) {
|
||||
const isApiRoute = req.path.startsWith('/api');
|
||||
const isLoginRoute = req.path.startsWith('/login') || req.path === '/auth/login.html';
|
||||
const isApiRoute = req.originalUrl.startsWith('/api');
|
||||
const isLoginRoute = req.originalUrl.startsWith('/login') || req.originalUrl === '/auth/login.html';
|
||||
|
||||
if (isLoginRoute || req.path === '/status') {
|
||||
if (isLoginRoute || req.originalUrl === '/status') {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ function authenticateToken(req, res, next) {
|
||||
// Verificar token
|
||||
jwt.verify(token, JWT_SECRET, (err, user) => {
|
||||
if (err) {
|
||||
if (req.path.startsWith('/api')) {
|
||||
if (req.originalUrl.startsWith('/api')) {
|
||||
return res.status(403).json({ error: 'Token inválido' });
|
||||
}
|
||||
return res.redirect('/login');
|
||||
|
||||
Reference in New Issue
Block a user