Tornando a função refreshSessions externa

This commit is contained in:
Matheus Albino Brunhara
2022-05-25 17:56:10 -05:00
parent 3c8e204339
commit f3969579f1
2 changed files with 52 additions and 12 deletions

View File

@@ -29,6 +29,7 @@ import * as usersRoutes from '../services/api/users';
import './Perfil.css'
import LocalStorage from "../LocalStorage";
import { refreshSession } from "../services/refreshSession";
const Perfil: React.FC = () => {
const [showToast, setShowToast] = useState(false);
@@ -57,19 +58,14 @@ const Perfil: React.FC = () => {
const loadUserData = async () => {
let userId = ''
await sessionRoutes.refresh().then(response => {
if (response.status === 'error') {
setMessageToast(response.message);
setShowToast(true);
return
}
userId = response.userId
}).catch(() => {
// verify if user is authenticated
const refreshedSession = await refreshSession()
if (refreshedSession.error) {
redirectUserToLogin()
})
return
}
await usersRoutes.getById(userId).then(response => {
if (response.status === 'error') {