chore: wrap function in try catch

This commit is contained in:
canove
2021-01-13 08:13:39 -03:00
parent 3aa287d394
commit ef6291c48d

View File

@@ -57,12 +57,17 @@ const useAuth = () => {
const token = localStorage.getItem("token"); const token = localStorage.getItem("token");
(async () => { (async () => {
if (token) { if (token) {
try {
const { data } = await api.post("/auth/refresh_token"); const { data } = await api.post("/auth/refresh_token");
api.defaults.headers.Authorization = `Bearer ${JSON.parse(token)}`; api.defaults.headers.Authorization = `Bearer ${data.token}`;
setIsAuth(true); setIsAuth(true);
setUser(data.user); setUser(data.user);
}
setLoading(false); setLoading(false);
} catch (err) {
toastError(err);
setLoading(false);
}
}
})(); })();
}, []); }, []);