-
-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get_current_user() is throwing a run-time error saying a @jwt.user_lookup_loader
callback must be defined, but it is defined
#408
Comments
Yeah, that was something that got changed. In 3.x.x, A stupid and yet easy way to work around this might be to add a Or perhaps we could introduce a new method that checks if there is a current user, or a setting that lets you toggled the behavior of Regardless, that error message is totally misleading. It should be saying something like |
What if the error said something like I think if I saw that it would have saved me around 30 minutes of debugging. |
That sounds great to me. Thanks for the feedback! 👍 |
Fixed in v4.2.0! |
Hi,
I'm upgrading from 3.x to 4.1.0 and I'm running into
RuntimeError: You must provide a @jwt.user_lookup_loader callback to use this method
. I'm getting this error when loading my login page which has a view of:Here's the route I took to try and narrow down the error:
return 'hey'
then the exception isn't thrown.login.html
template and make thebody
block empty, then the exception is thrown.login.html
template and don't pull in my layout then the exception isn't thrown.current_user.username
) then the exception isn't thrown and I'm able to login and everything works.So there's something about reading that current_user that used to work in 3.x that's not working anymore in 4.x and it's causing things to blow up. The code in the template is
href="{{ url_for('facts.index', username=current_user.username) }}"
. This works when I'm logged in but not when I'm logged out.It used to work in both cases with 3.x. I am using JS to toggle the visibility of some menu items based on being logged in or not. I know I can likely alter the logic to check if there's a
current_user
at the Jinja level but I'm trying to streamline the UI a bit with JS and if a bad actor unhid the nav items as a logged out user it wouldn't do any harm. Any thoughts on how to get this to work with 4.x?Here's what I've done so far:
@jwt_required
to@jwt_required()
in every spotIn my old 3.x code, I had this in my callbacks:
In the new 4.x code, I've changed that to:
In both cases this
jwt_callbacks()
function is being called in mycreate_app()
function which is the set up I was using with 3.x that worked.As for using the required decorators, this all worked in the 3.x code using this code style:
In the 4.x upgrade I'm doing the same ordering except now I'm calling
jwt_required()
. In the cases where I am using optional authentication I've changed those tojwt_required(optional=True)
as per the upgrade guide.Here's the full stack trace which is interesting because it's saying I'm trying to use
get_current_user()
but the callback isn't defined, however that callback is defined.As for settings, the only ones I've set are:
Any ideas?
The text was updated successfully, but these errors were encountered: