Help me fox eslint error - promises must be awaited

Help me fix this error
Error: Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator. @typescript-eslint/no-floating-promises
Error: Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator. @typescript-eslint/no-floating-promises
I have this code
import { useEffect } from "react";
import useUserStore from "~/store/useUserStore";
import supabase from "~/utils/supabaseClient";

const useAuthorized = () => {
const userStore = useUserStore();

useEffect(() => {
const checkAuthorization = async () => {
try {
const response = await supabase.auth.getUser();
if (response.data.user) {
userStore.setIsAuthenticatedTrue();
userStore.setUserId(response.data.user?.id);
const { data } = await supabase.from("users")
.select("profile_picture_url")
.eq("userId", userStore.userId)
if (data) {
userStore.setProfilePictureUrl(data[0]?.profile_picture_url as string);
}
}
} catch (error) {
console.error("checkAuthorization - " , error)
}
}
checkAuthorization();
}, []);
};

export default useAuthorized;
import { useEffect } from "react";
import useUserStore from "~/store/useUserStore";
import supabase from "~/utils/supabaseClient";

const useAuthorized = () => {
const userStore = useUserStore();

useEffect(() => {
const checkAuthorization = async () => {
try {
const response = await supabase.auth.getUser();
if (response.data.user) {
userStore.setIsAuthenticatedTrue();
userStore.setUserId(response.data.user?.id);
const { data } = await supabase.from("users")
.select("profile_picture_url")
.eq("userId", userStore.userId)
if (data) {
userStore.setProfilePictureUrl(data[0]?.profile_picture_url as string);
}
}
} catch (error) {
console.error("checkAuthorization - " , error)
}
}
checkAuthorization();
}, []);
};

export default useAuthorized;
this line cause eslint error
checkAuthorization();
checkAuthorization();
2 Replies
Joao
Joao16mo ago
Any function that uses async returns a Promise. You need to use await checkAuthorization or then and catch.
Nikita
NikitaOP16mo ago
ChatGPT4 helped me fix it
void checkAuthorization().catch(console.error)
void checkAuthorization().catch(console.error)
instead of
checkAuthorization();
checkAuthorization();
yes you'r right if you provide example next time would be very nice
Want results from more Discord servers?
Add your server