Skip to content

Commit

Permalink
fix: added support for inner handler as sync
Browse files Browse the repository at this point in the history
  • Loading branch information
IA-PieroCV committed Dec 3, 2024
1 parent c71ba65 commit a88e96c
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions robyn/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,21 +289,32 @@ def add_auth_middleware(self, endpoint: str):
injected_dependencies: dict = {}

def decorator(handler):
@wraps(handler)
async def inner_handler(request: Request, *args):
if not self.authentication_handler:
raise AuthenticationNotConfiguredError()
if inspect.iscoroutinefunction(self.authentication_handler.authenticate):

@wraps(handler)
async def inner_handler(request: Request, *args):
if not self.authentication_handler:
raise AuthenticationNotConfiguredError()

if inspect.iscoroutinefunction(self.authentication_handler.authenticate):
identity = await self.authentication_handler.authenticate(request)
else:
identity = self.authentication_handler.authenticate(request)
if identity is None:
return self.authentication_handler.unauthorized_response
request.identity = identity

if identity is None:
return self.authentication_handler.unauthorized_response
request.identity = identity
return request
else:

@wraps(handler)
def inner_handler(request: Request, *args):
if not self.authentication_handler:
raise AuthenticationNotConfiguredError()

identity = self.authentication_handler.authenticate(request)
if identity is None:
return self.authentication_handler.unauthorized_response
request.identity = identity

return request
return request

self.add_route(
MiddlewareType.BEFORE_REQUEST,
Expand Down

0 comments on commit a88e96c

Please sign in to comment.