Correção perfil
This commit is contained in:
@@ -60,22 +60,28 @@ const Perfil: React.FC = () => {
|
||||
let userId = ''
|
||||
|
||||
// verify if user is authenticated
|
||||
const refreshedSession = await refreshSession()
|
||||
const refreshSessionRes = await refreshSession()
|
||||
|
||||
if (refreshedSession.error) {
|
||||
if (refreshSessionRes.error) {
|
||||
redirectUserToLogin()
|
||||
return
|
||||
}
|
||||
|
||||
await usersRoutes.getById(userId).then(response => {
|
||||
if (response.status === 'error') {
|
||||
setMessageToast(response.message.data)
|
||||
setShowToast(true);
|
||||
if (refreshSessionRes.userId) {
|
||||
userId = refreshSessionRes.userId
|
||||
}
|
||||
|
||||
// get user info by ID
|
||||
const getByIdRes = await usersRoutes.getById(userId)
|
||||
|
||||
if (getByIdRes.error) {
|
||||
setMessageToast(getByIdRes.message.data)
|
||||
setShowToast(true)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const userData = response.data
|
||||
const userData = getByIdRes.data
|
||||
|
||||
setInputValues({
|
||||
'name': userData.name,
|
||||
@@ -84,9 +90,6 @@ const Perfil: React.FC = () => {
|
||||
'birth_date': userData.birth_date,
|
||||
'bio': userData.bio
|
||||
});
|
||||
}).catch(() => {
|
||||
redirectUserToLogin()
|
||||
})
|
||||
}
|
||||
|
||||
const userToken = LocalStorage.getToken()
|
||||
@@ -95,7 +98,6 @@ const Perfil: React.FC = () => {
|
||||
redirectUserToLogin()
|
||||
}
|
||||
|
||||
// const refreshResponse = refreshSession()
|
||||
loadUserData()
|
||||
}, [history]);
|
||||
|
||||
|
||||
35
src/services/users/getById.ts
Normal file
35
src/services/users/getById.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import * as usersRoutes from "../../services/api/users";
|
||||
|
||||
interface getByIdReturn {
|
||||
userId?: string;
|
||||
error?: boolean;
|
||||
errorMessage?: string;
|
||||
}
|
||||
|
||||
interface getByIdResponse {
|
||||
status?: string;
|
||||
message?: string;
|
||||
userId?: string;
|
||||
}
|
||||
|
||||
export const getById = async (userId: string): Promise<getByIdReturn> => {
|
||||
try {
|
||||
let res: getByIdResponse = await usersRoutes.getById(userId)
|
||||
|
||||
if (res.status === "error") {
|
||||
return {
|
||||
error: true,
|
||||
errorMessage: res.message,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
userId: res.userId,
|
||||
};
|
||||
} catch(err) {
|
||||
return {
|
||||
error: true,
|
||||
errorMessage: "Por favor, autentique-se.",
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user