Fixed middleware authentication issues
This commit is contained in:
@@ -31,7 +31,8 @@ from app.exceptions import (
|
||||
InvalidTokenException,
|
||||
TokenExpiredException,
|
||||
UserNotActiveException,
|
||||
InvalidCredentialsException
|
||||
InvalidCredentialsException,
|
||||
InsufficientPermissionsException
|
||||
)
|
||||
from models.database.user import User
|
||||
|
||||
@@ -223,6 +224,9 @@ class AuthManager:
|
||||
# Token signature verification failed or token is malformed
|
||||
logger.error(f"JWT decode error: {e}")
|
||||
raise InvalidTokenException("Could not validate credentials")
|
||||
except (InvalidTokenException, TokenExpiredException):
|
||||
# Re-raise our custom exceptions with their original messages
|
||||
raise
|
||||
except Exception as e:
|
||||
# Catch any other unexpected errors during token verification
|
||||
logger.error(f"Token verification error: {e}")
|
||||
@@ -334,7 +338,6 @@ class AuthManager:
|
||||
"""
|
||||
# Check if user has vendor or admin role (admins have full access)
|
||||
if current_user.role not in ["vendor", "admin"]:
|
||||
from app.exceptions import InsufficientPermissionsException
|
||||
raise InsufficientPermissionsException(
|
||||
message="Vendor access required",
|
||||
required_permission="vendor"
|
||||
@@ -358,7 +361,6 @@ class AuthManager:
|
||||
"""
|
||||
# Check if user has customer or admin role (admins have full access)
|
||||
if current_user.role not in ["customer", "admin"]:
|
||||
from app.exceptions import InsufficientPermissionsException
|
||||
raise InsufficientPermissionsException(
|
||||
message="Customer account access required",
|
||||
required_permission="customer"
|
||||
|
||||
Reference in New Issue
Block a user