app_2.py 515 B

12345678910111213141516171819
  1. def decorator(*args, **kwargs):
  2. token = None
  3. if 'Authorization' in request.headers:
  4. token = request.headers['Authorization'].split(' ')[1]
  5. if not token:
  6. return jsonify({'message': 'a valid token is missing'})
  7. try:
  8. data = jwt.decode(token.encode('UTF-8'), 'SECRET', algorithm='HS256')
  9. print("logged in user is ")
  10. print(data)
  11. except Exception as e:
  12. print(e)
  13. return jsonify({'message': 'token is invalid'})
  14. return f(*args, **kwargs)