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
Joao10mo ago
Any function that uses async returns a Promise. You need to use await checkAuthorization or then and catch.
Nikita
Nikita10mo 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
More Posts
I am creating a form for uploading data in a dashboardWant to know if any styling improvements can be done to the following UIBackground color for right sideThere is a white space on right section i want to apply background color to cover the whole sectiopick a project card layout for melive icon is to jump to live website github icon is to github repo the rest of icons are stacks usedHow to cause transition to happen from the center instead of top left?The eyeballs come into existence from the corners respectively, how would I make them pop out from tImage in flexbox.In the Hero section I would like to align the Image with the bottom of the container (border-bottom i want to change the style of slider like the slider in the link https://aleksfedotov.github.io/passi want to change the style of slider like the slider in the link https://aleksfedotov.github.io/passNow a days I am using sass but I don't understand why should I use !important to apply the style.It doesn't work until I give !important I have to use 2 time !important specially when I want to setSave images from file input in form POST methodSo recently I've been learning express JS and wanted to do a simple project of making a website withDisable Scrolling for a Mat Dialog in the backdropAm trying to disable page scrolling when Mat Dialog is opened . Tried overflow:hidden but it didn't How to nest element between content and router (react-router-dom v6)I am trying to build react web, where is element (`Provider`) nested between router, so the element