export async function getSessionGuild() { const { data: session } = await getSession(); if (!session) return { dataGuild: null, status: null } const getGuilds = await session.user?.guilds.map((i) => i.id); const getGuild = await Promise.all( getGuilds.map((guildId) => { return fetch("https://api.com/getguilds", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ guildId: guildId }), }) .then((res) => { return res.json(); }) .then((response) => { if (!response.data) return; return { id: guildId, status: response.data, }; }).catch((err) => console.log(err)); }) ); const getRealData = getGuild.map((i) => { try { if (i.status !== "Found") { return { id: i.id, status: "NotFound" } } else { return { id: i.id, status: "Found" } } } catch (err) { return "err"; } }); const getissue = getRealData.includes("err"); if (getissue) return { dataGuild: null, status: null, } return { dataGuild: session.user.guilds, status: getRealData, } }