diff --git a/services/auth.py b/services/auth.py index d2bd6c1..92596a0 100644 --- a/services/auth.py +++ b/services/auth.py @@ -60,15 +60,13 @@ def login_required(f): info = args[1] context = info.context req = context.get("request") - authorized = await check_auth(req) - if authorized: - user_id, user_roles = authorized - if user_id and isinstance(user_id, str): - context["user_id"] = user_id.strip() - author = get_author_by_user(user_id) - if author and "id" in author: - context["author_id"] = author["id"] - return await f(*args, **kwargs) + user_id, user_roles = await check_auth(req) + if user_id and isinstance(user_id, str): + context["user_id"] = user_id.strip() + author = get_author_by_user(user_id) + if author and "id" in author: + context["author_id"] = author["id"] + return await f(*args, **kwargs) else: raise HTTPException(status_code=401, detail="Unauthorized") @@ -79,16 +77,12 @@ def auth_request(f): @wraps(f) async def decorated_function(*args, **kwargs): req = args[0] - authorized = await check_auth(req) - if authorized: - user_id, user_roles = authorized - if user_id and isinstance(user_id, str): - user_id = user_id.strip() - author = get_author_by_user(user_id) - if author and "id" in author: - req["author_id"] = author["id"] - else: - logger.error('cannot find author') + user_id, user_roles = await check_auth(req) + if user_id and isinstance(user_id, str): + user_id = user_id.strip() + author = get_author_by_user(user_id) + if author and "id" in author: + req["author_id"] = author["id"] return await f(*args, **kwargs) else: raise HTTPException(status_code=401, detail="Unauthorized")