Im trying to attach a token to a logged in user:
user_info = request.get_json()
entered_username = User.query.filter_by(username = user_info['username']).first()
if user_info['password'] == entered_username.password:
token = jwt.encode({'username':entered_username, 'exp':datetime.datetime.utcnow() + datetime.timedelta(minutes=30)},
secret_key, algorithm='HS256').decode('UTF-8')
return jsonify(token)
But i get: TypeError: Object of type 'User' is not JSON serializable.
I've also tried to do return jsonify(token.decode('UTF-8'))
What am i missing?
Userobject to JSON andentered_usernameis aUserobject. If you just want the username in your token, encode{'username': user_info['username'], ...}.{'username': user_info['username'], ...}.decode('UTF-8') but then i get AttributeError: 'dict' object has no attribute 'decode'.... I'm also not sure why you're trying to calldecodehere.