Session did not persist when using blueprints #769
Closed
magloiretouh
started this conversation in
General
Replies: 1 comment
-
I find the solution, we need to add credentials: 'include' to every request done with fetch in js. I did not add it to the login request.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi All,
@login_required is causing 401 unauthorized error for other blueprints in my app. different session is generated for each blueprint.
Find below the session create in user blueprint after login and the one create in another blueprint.
<FileSystemSession {'_permanent': True, '_user_id': '1', '_fresh': True, '_id': 'cccb4b6f7b79524eb989863282335583c7824ccff9039198aba43a5b82216121a6338417c7861a869007264c37311e2263718cf7668fb68f60e25592c2ddce16'}>
<FileSystemSession` {'_permanent': True}>
Login blueprint and code
`user_bp = Blueprint("user", name)
@user_bp.route('/login', methods=['POST'])
def login():
data = request.form
`
Other blueprint
`fund_request_bp = Blueprint("fund_request", name, url_prefix="/fund_requests")
@fund_request_bp.route("/", methods=["GET"])
@login_required
def get_all_fund_request():
fund_requests = FundRequest.query.filter_by(approval_level=current_user.user_level.level)
`
App config
app = Flask(__name__) app.config['SECRET_KEY'] = 'some_secret_key' app.config['SESSION_TYPE'] = 'filesystem' app.config['SESSION_COOKIE_PATH'] = '/' login_manager = LoginManager(app) CORS(app, supports_credentials=True) Session(app)
Ps: I used postman for tests and did not get any issue
Can Flask_login works with blueprints ? if yes, what is the standard way to do it
Beta Was this translation helpful? Give feedback.
All reactions