'AttributeError: 'NoneType' object has no attribute 'verified_email'

I am trying to create a decorator function, which checks if user's email is verified, but I am getting this error.

AttributeError: 'NoneType' object has no attribute 'verified_email'

Does somebody know how to solve it?

def email_verified(func):
    def check_verification():
        user = current_user
        if user.verified_email == True:
            return func()
        else:
            flash("verify your email")
            return redirect(url_for(index))
    return check_verification()


Solution 1:[1]

The definition needs the current_user as some kind of input.

Solution 2:[2]

Try adding a check like this

...
        if user and user.verified_email:
            return func()
        else:
...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pydragon
Solution 2 Diego Torres Milano