You must understand that for one application you must use one login manager no matter how many blueprints you use (of course there can be specific exceptions for example when blueprints are independent, but in this case you probably can't use flask-login
). Because:
- You have 1 entry point
- If user is not logged in, he will be redirected to login/registration page
- You have 1 user loader
How login manager works:
- It registers
current_user
in request context before_request
reads your session, gets user id, loads the user withuser_loader
and set it tocurrent_user
orAnonymousUser
- When you visit the private page,
login_required
checkscurrent_user.is_authenticated()
else redirects to login page - On login, it adds user id to the session
So you must initialize only one login manager instance for flask application and then use login_required
and current_user
in all your blueprints.