Reputation: 451
I have app where before request i check if JWT token is present in request. If the token is present I check for the user and if I get the user I want to redirect user to URL that he wanted to access if token isn't present redirect user to login page.
The problem is when I'm trying to redirect the request.endpoint is None
The problem goes away when Im not passing bearer token into request
code
view_endpoints = ['views.task', 'views.tests']
@jwt_required(optional=True)
@app.before_request
def require_authorization():
if optional_jwt():
username = get_jwt_identity()
if username:
return redirect(request_flask.endpoint)
if request_flask.endpoint not in view_endpoints:
logged = current_user.is_authenticated
if not logged:
return redirect('/login')
Im passing token via postman auth tab
Upvotes: 1
Views: 104