Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up@inject_user() decorator hangs for me #114
Comments
This comment has been minimized.
This comment has been minimized.
ok, i've found a solution, my retrieve_user function was not async |
This comment has been minimized.
This comment has been minimized.
Hello, @gbnk0 ! Sorry for this late answer, I was not around my computer. AFAIK, there should not be any problems if your I'll leave this issue open for @ahopkins knowledge. Thanks a lot for your time and patience reporting these "misbehavior" with us |
This comment has been minimized.
This comment has been minimized.
@gbnk0 and @vltr
Or, an awaitable:
Furthermore, if it is returning an object, the @gbnk0, if you wouldn't mind, can you send me your |
This comment has been minimized.
This comment has been minimized.
Hi, Here is my (dirty) code snippet: def retrieve_user(request, payload, *args, **kwargs):
result = None
if payload:
user_id = payload.get('user_id', None)
if user_id != None:
user = db.get_user(user_id=user_id)
# Remove password from returned user
if type(user) == dict:
user.pop('password', None)
result = user
return result and the initialize: initialize(app,
authenticate,
store_refresh_token=store_refresh_token,
retrieve_refresh_token=retrieve_refresh_token,
retrieve_user=retrieve_user,
class_views=custom_views,
add_scopes_to_payload=scope_extender
) Regards, |
This comment has been minimized.
This comment has been minimized.
And i have the error when i try a blueprint route: # Fetch current user details
@blueprint_me.get("")
@inject_user()
@protected()
async def get_user_details_route(request, user):
return get_my_details(request, user, es)
|
This comment has been minimized.
This comment has been minimized.
@gbnk0 Thank you! I found the bug. user = await instance.auth.retrieve_user(request, payload) This should be executed with The line should be: user = await utils.call(instance.auth.retrieve_user, request, payload) My bad. Thanks for pointing it out. |
ahopkins
added
bug
help wanted
good for first timers
labels
Jun 18, 2018
This comment has been minimized.
This comment has been minimized.
Can i inject_user on an entire blueprint? |
This comment has been minimized.
This comment has been minimized.
The from sanic import Sanic
from sanic.response import text
from sanic.views import HTTPMethodView
from sanic_jwt import inject_user
from sanic import Blueprint
app = Sanic('myapp')
bp = Blueprint('mybp')
class MyBaseHTTPView(HTTPMethodView):
decorators = [inject_user(), ]
class SomeBPView(MyBaseHTTPView):
async def get(self, request, user):
return text(f'Hello {user.username}')
bp.add_route(SomeBPView.as_view(), '/')
app.blueprint(bp) I have not tried this. But, it should look something like this. |
This comment has been minimized.
This comment has been minimized.
Ok i'll try this, thanks |
ahopkins
closed this
in
14780ca
Aug 5, 2018
This comment has been minimized.
This comment has been minimized.
This should be resolved in the latest commits. |
gbnk0 commentedJun 15, 2018
Hi i'm back with another issue, i use @inject_user on a route, it give me this message:
Here's my snippet: