gpt4 book ai didi

javascript - flask-security ajax 注销导致 session 错误

转载 作者:行者123 更新时间:2023-11-28 19:29:37 25 4
gpt4 key购买 nike

当我发布到 flask 端点时:

@app.route('/api/v1/logout', methods=['POST','GET'])
def logout():
logout_user()
return jsonify(status=200, message='User has been successfully logged out.')

下次尝试登录时出现错误

InvalidRequestError: Object '<User at 0x7f09b4831c90>' is already attached to session '1' (this is '4')

我想知道如何注销并安全地使用 ajax。

编辑- angularjs 登录 Controller :

LoginController: function ($scope, $http, authService, $location) {
$scope.submit = function() {
console.log('in logincontroller')
$http.defaults.headers.post['X-CSRFToken'] = csrf_token;
$http.defaults.headers.common['Content-Type'] = 'application/json'
//debugger;
$http.post(
'/login',
JSON.stringify({ email: $scope.email, password: $scope.password })
).success(
function(data) {
if (data.meta){
var status_code = data.meta.code;
}
else{
var status_code = data.status;
}
if (status_code == 200){
$.cookie('email', $scope.email, { expires: 7 });
$.cookie('auth_token', data.authentication_token, { expires: 7 });
$http.defaults.headers.common['Authentication-Token'] = data.authentication_token;
authService.loginConfirmed();
$location.path("/dashboard");
}
else{
//form stuff
}
}
).error(
function(data) {
alert('LoginController submit error');
$scope.errorMsg = data.reason;
//debugger;
}
);
};
}

最佳答案

我想你必须在最后重定向才能退出现有 session

@app.route('/logout')
def logout():
# remove the username from the session if it's there
session.pop('username', None)
return redirect(url_for('index'))

关于javascript - flask-security ajax 注销导致 session 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20983588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com