Erro de login
This commit is contained in:
parent
844ebf03a8
commit
95054bb9c1
@ -24,7 +24,7 @@ return(
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
||||||
{showModal ?
|
{showModal === "modal"?
|
||||||
|
|
||||||
<div className="modal-overlay">
|
<div className="modal-overlay">
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
import React, { useState, useEffect, use } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
import { useAuth } from "../components/utils/AuthProvider";
|
import { useAuth } from "../components/utils/AuthProvider";
|
||||||
import API_KEY from "../components/utils/apiKeys";
|
import API_KEY from "../components/utils/apiKeys";
|
||||||
import { UserInfos } from "../components/utils/Functions-Endpoints/General";
|
import { UserInfos } from "../components/utils/Functions-Endpoints/General";
|
||||||
|
import CabecalhoError from "../components/utils/fetchErros/CabecalhoError";
|
||||||
|
|
||||||
function Login({ onEnterSystem }) {
|
function Login({ onEnterSystem }) {
|
||||||
const { setAuthTokens } = useAuth();
|
const { setAuthTokens } = useAuth();
|
||||||
|
const [showCabecalho, setShowCabecalho ] = useState(false)
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [form, setForm] = useState({
|
const [form, setForm] = useState({
|
||||||
username: "",
|
username: "",
|
||||||
@ -126,6 +128,9 @@ function Login({ onEnterSystem }) {
|
|||||||
} else if (UserData?.roles?.includes("financeiro")) {
|
} else if (UserData?.roles?.includes("financeiro")) {
|
||||||
navigate(`/financeiro/`);
|
navigate(`/financeiro/`);
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
console.log("ERROROROROROOR")
|
||||||
|
setShowCabecalho(true)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setAlert("Preencha todos os campos!");
|
setAlert("Preencha todos os campos!");
|
||||||
@ -148,11 +153,7 @@ function Login({ onEnterSystem }) {
|
|||||||
<p className="auth-subtitle mb-5">
|
<p className="auth-subtitle mb-5">
|
||||||
Entre com os dados que você inseriu durante o registro.
|
Entre com os dados que você inseriu durante o registro.
|
||||||
</p>
|
</p>
|
||||||
{alert && (
|
<CabecalhoError showCabecalho={showCabecalho} message={"E-mail ou senha incorretos."}/>
|
||||||
<div className="alert alert-info" role="alert">
|
|
||||||
{alert}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<form onSubmit={handleLogin}>
|
<form onSubmit={handleLogin}>
|
||||||
<div className="form-group position-relative has-icon-left mb-4">
|
<div className="form-group position-relative has-icon-left mb-4">
|
||||||
<input
|
<input
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import API_KEY from "../components/utils/apiKeys";
|
|||||||
import { useAuth } from "../components/utils/AuthProvider";
|
import { useAuth } from "../components/utils/AuthProvider";
|
||||||
import "./style/TablePaciente.css";
|
import "./style/TablePaciente.css";
|
||||||
import ModalErro from "../components/utils/fetchErros/ModalErro";
|
import ModalErro from "../components/utils/fetchErros/ModalErro";
|
||||||
|
import manager from "../components/utils/fetchErros/ManagerFunction";
|
||||||
|
|
||||||
function TablePaciente({ setCurrentPage, setPatientID }) {
|
function TablePaciente({ setCurrentPage, setPatientID }) {
|
||||||
|
|
||||||
const { getAuthorizationHeader, isAuthenticated, RefreshingToken } = useAuth();
|
const { getAuthorizationHeader, isAuthenticated, RefreshingToken } = useAuth();
|
||||||
@ -24,7 +26,7 @@ function TablePaciente({ setCurrentPage, setPatientID }) {
|
|||||||
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
||||||
const [selectedPatientId, setSelectedPatientId] = useState(null);
|
const [selectedPatientId, setSelectedPatientId] = useState(null);
|
||||||
|
|
||||||
const [showModalError, setShowModalError] = useState(false);
|
const [showModalError, setShowModalError] = useState("");
|
||||||
|
|
||||||
const [ ErrorInfo, setErrorInfo] = useState({})
|
const [ ErrorInfo, setErrorInfo] = useState({})
|
||||||
|
|
||||||
@ -117,7 +119,7 @@ function TablePaciente({ setCurrentPage, setPatientID }) {
|
|||||||
redirect: 'follow'
|
redirect: 'follow'
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch("https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/patients", requestOptions)
|
fetch("https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/patient", requestOptions)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
||||||
// 1. VERIFICAÇÃO DO STATUS HTTP (Se não for 2xx)
|
// 1. VERIFICAÇÃO DO STATUS HTTP (Se não for 2xx)
|
||||||
@ -142,21 +144,15 @@ function TablePaciente({ setCurrentPage, setPatientID }) {
|
|||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
// 4. Bloco de SUCESSO
|
|
||||||
setPacientes(result);
|
setPacientes(result);
|
||||||
console.log("Sucesso:", result);
|
console.log("Sucesso:", result);
|
||||||
|
|
||||||
// IMPORTANTE: Se o modal estava aberto, feche-o no sucesso
|
|
||||||
setShowModalError(false);
|
setShowModalError(false);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
// 5. Bloco de ERRO (Captura erros de rede ou o erro lançado pelo 'throw')
|
manager(setShowModalError, RefreshingToken, setErrorInfo, error)
|
||||||
//console.error('Falha na requisição:', error.message);
|
|
||||||
if(error.httpStatus === 401){
|
|
||||||
RefreshingToken()
|
|
||||||
}
|
|
||||||
setErrorInfo(error)
|
|
||||||
setShowModalError(true);
|
|
||||||
});
|
});
|
||||||
}, [isAuthenticated, getAuthorizationHeader]);
|
}, [isAuthenticated, getAuthorizationHeader]);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user