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) {
const { data } = await api.post("/auth/refresh_token"); try {
api.defaults.headers.Authorization = `Bearer ${JSON.parse(token)}`; const { data } = await api.post("/auth/refresh_token");
setIsAuth(true); api.defaults.headers.Authorization = `Bearer ${data.token}`;
setUser(data.user); setIsAuth(true);
setUser(data.user);
setLoading(false);
} catch (err) {
toastError(err);
setLoading(false);
}
} }
setLoading(false);
})(); })();
}, []); }, []);