I'm trying to decode a JWT token using Flask-JWT-Extended's decode_token() function, but it's returning a function object instead of the decoded token. Here's my code:
@app.route("/resend-verification-email", methods=("GET", "POST"))
def resend_verification_email():
if current_user.is_authenticated:
access_token = create_access_token(identity=current_user.id)
verification_url = f"http://localhost:5000/verify-email/verify?token={access_token}"
msg = Message("Welcome to Shortify", sender="test@gmail.com", recipients=[current_user.email])
msg.html = render_template("/email.html", user=current_user, verification_url=verification_url)
mail.send(msg)
flash("Verification email sent", "success")
return redirect(url_for("index_view"))
return redirect(url_for("login_view"))
@app.route("/verify-email/verify", methods=("GET", "POST"))
def verify_email():
token = request.args.get("token")
try:
decoded_token = decode_token(token)
user_id = decoded_token["identity"]
user = models.User.query.get(user_id)
user.email_verified = True
user.save()
flash("Email verified successfully", "success")
return redirect(url_for("index_view"))
except Exception as e:
print(e)
flash("Invalid or expired token", "danger")
return redirect(url_for("index_view"))
The print statement is outputting <function decode_token at 0x7fb5dc45ca60>
instead of the decoded token. I'm not sure what I'm doing wrong. Can anyone help?