'Flask cookies set in Postman but not in browser
I've problem with Flask cookies, my routes is working in Postman but when I tried to test with my front-end, my cookie doesn't set.
This is my route to connect user :
@users.route('/api/user/login', methods=['POST'])
def check_password():
req = request.get_json()
email = req['email']
password = req['password']
query = Users().get_by_email(email)
if query:
if bcrypt.check_password_hash(query['password'], password):
res = make_response("Vous êtes connecté")
res.set_cookie('status', 'connected', max_age=60 * 60 * 24 * 365 * 2, domain='127.0.0.1')
session.modified = True
return res
else:
return "Password incorect"
else:
return "Pas d'utilisateur"
This is my route to check the user status (to know if cookie is set or not) :
@users.route('/api/user/status', methods=['GET'])
def status():
if request.cookies.get('status'):
return "Connecté"
else:
return "Pas encore connecté"
And this is the AJAX request in my front to call my route :
userStatus() {
$.ajax({
method: "GET",
url: "http://localhost:8080/api/user/status",
})
.done((data) => {
console.log(data);
})
.fail(() => {
console.log("PAS OK")
})
}
If someone can help me about this problem it will be very nice. Thank you !
Solution 1:[1]
Did you enabled CORS ? because when you are calling with javascript a api, you will need to enable CORS to make javascript calls to your server
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 | Nilesh.py |
