Python:
data = request.get_json()
user = data.get("user")
password = data.get("password")
# Compara as credenciais
if user == valid_user["username"] and password == valid_user["password"]:
session['usuario_logado'] = user
return jsonify({"result": "OK", "message": f"Bem-Vindo, {session['usuario_logado']}"}), 200
React:
try {
const response = await fetch('http://127.0.0.1:8000/login', {
method: 'POST',
headers: {
'Content-type': 'application/json',
},
body: JSON.stringify(formData),
});
const data = await response.json(); // Lê o corpo da resposta como JSON
console.log(`response: ${response}\n
response.json: ${response.json()}\n
data.result: ${data.result}\n`)
if (response.ok) {
if (data.result === 'OK') {
navigate('/login/register');
window.alert(data.message);
}