Skip to content

Instantly share code, notes, and snippets.

@aeruo
Created September 8, 2023 11:02
Show Gist options
  • Save aeruo/831a095d714c115e9dee2c39bb3070d4 to your computer and use it in GitHub Desktop.
Save aeruo/831a095d714c115e9dee2c39bb3070d4 to your computer and use it in GitHub Desktop.
Python decorator function to require login.
def login_required(f):
"""
Decorate routes to require login.
http://flask.pocoo.org/docs/1.0/patterns/viewdecorators/
"""
@wraps(f)
def decorated_function(*args, **kwargs):
if session.get("user_id") is None:
return redirect("/")
return f(*args, **kwargs)
return decorated_function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment