Fix: Cleanup and SSR auth header fix
This commit is contained in:
parent
b28ceb8659
commit
2b9b5198fa
5 changed files with 92 additions and 128 deletions
|
@ -46,13 +46,13 @@ async function getUser() {
|
|||
}
|
||||
|
||||
function NavUser() {
|
||||
const [user] = createResource(() =>
|
||||
getUser().then((e) => {
|
||||
if (!e.success) console.log(1, e.message);
|
||||
console.log(2, e);
|
||||
return e;
|
||||
}),
|
||||
);
|
||||
const [user] = createResource(async () => {
|
||||
const user = await getUser();
|
||||
|
||||
if (!user.success) console.error("userInfo", user.message);
|
||||
|
||||
return user;
|
||||
});
|
||||
|
||||
return (
|
||||
<Show
|
||||
|
|
|
@ -29,8 +29,6 @@ export const GET = async (
|
|||
{ success: false; message: string } | (data & { success: true })
|
||||
> => {
|
||||
const id = event.params.guildId;
|
||||
// const id = "598539452343648256";
|
||||
// const location = useLocation();
|
||||
if (!event) return { success: false, message: "No request event!" };
|
||||
|
||||
const session = await getSession(event.request, authOptions);
|
||||
|
@ -62,9 +60,8 @@ export const GET = async (
|
|||
},
|
||||
headers: { Authorization: `Bot ${import.meta.env.VITE_DISCORD_BOT_TOKEN}` },
|
||||
});
|
||||
|
||||
if (guildsRequest.error || channelsRequest.error) {
|
||||
console.log(guildsRequest.error, channelsRequest.error, location.pathname);
|
||||
console.log(guildsRequest.error, channelsRequest.error, event.path);
|
||||
return {
|
||||
success: false,
|
||||
message: "Error on one of the discord api requests!",
|
||||
|
@ -94,8 +91,6 @@ export const GET = async (
|
|||
});
|
||||
});
|
||||
|
||||
console.log("done");
|
||||
|
||||
return {
|
||||
success: true,
|
||||
guild: {
|
||||
|
|
|
@ -45,8 +45,6 @@ export const GET = async (
|
|||
headers: { Authorization: `Bearer ${DISCORD_ACCESS_TOKEN}` },
|
||||
});
|
||||
|
||||
console.log("guilds", guilds);
|
||||
|
||||
if (error) {
|
||||
console.log(error);
|
||||
return { success: false, message: "Error on discord api request!" };
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
createSignal,
|
||||
} from "solid-js";
|
||||
import { createStore } from "solid-js/store";
|
||||
import { getRequestEvent } from "solid-js/web";
|
||||
import { FontAwesomeIcon } from "~/components/FontAwesomeIcon";
|
||||
import Layout from "~/components/Layout";
|
||||
import "../../styles/pages/config.scss";
|
||||
|
@ -30,6 +31,8 @@ function config() {
|
|||
const params = useParams();
|
||||
const navigator = useNavigate();
|
||||
const location = useLocation();
|
||||
const event = getRequestEvent();
|
||||
|
||||
const [timezoneRef, setTimezoneRef] = createSignal<HTMLInputElement>();
|
||||
const [timePlanningRef, setTimePlanningRef] =
|
||||
createSignal<HTMLInputElement>();
|
||||
|
@ -41,7 +44,9 @@ function config() {
|
|||
const [payload] = createResource(
|
||||
params.guildId,
|
||||
async (id) => {
|
||||
const payload = await fetch(`http://localhost:3000/api/config/${id}`)
|
||||
const payload = await fetch(`http://localhost:3000/api/config/${id}`, {
|
||||
headers: event?.headers,
|
||||
})
|
||||
.then(
|
||||
(res) =>
|
||||
res.json() as Promise<
|
||||
|
@ -56,17 +61,24 @@ function config() {
|
|||
)
|
||||
.catch((e) => console.warn(e, id));
|
||||
|
||||
if (!payload) return initialValue(params);
|
||||
if (!payload) {
|
||||
console.error(location.pathname, payload);
|
||||
return initialValue(params);
|
||||
}
|
||||
|
||||
if (!payload.success) {
|
||||
console.log(payload);
|
||||
console.log(location.pathname, payload.message, "No success");
|
||||
// navigator("/config", { replace: false });
|
||||
navigator("/config", { replace: false });
|
||||
return initialValue(params);
|
||||
}
|
||||
|
||||
return payload;
|
||||
},
|
||||
{ initialValue: initialValue(params) },
|
||||
{
|
||||
initialValue: initialValue(params),
|
||||
deferStream: true,
|
||||
},
|
||||
);
|
||||
const [config, setConfig] = createStore({
|
||||
features: {
|
||||
|
@ -78,53 +90,13 @@ function config() {
|
|||
},
|
||||
});
|
||||
|
||||
createEffect(() => console.log(payload.loading, payload()));
|
||||
createEffect(() => console.log("timezone", timezone()));
|
||||
createEffect(() =>
|
||||
console.log("timePlanning.enabled", config.features.timePlanning.enabled),
|
||||
);
|
||||
createEffect(() =>
|
||||
console.log(
|
||||
"timePlanning.channelId",
|
||||
config.features.timePlanning.channelId,
|
||||
),
|
||||
);
|
||||
createEffect(() =>
|
||||
console.log(
|
||||
"timePlanning.pingableRoles",
|
||||
config.features.timePlanning.pingableRoles,
|
||||
),
|
||||
);
|
||||
|
||||
createEffect(() => {
|
||||
const ref = timezoneRef();
|
||||
if (!ref) return;
|
||||
ref.value = timezone();
|
||||
});
|
||||
createEffect(() => {
|
||||
const ref = timePlanningRef();
|
||||
if (!ref) return;
|
||||
ref.checked = config.features.timePlanning.enabled;
|
||||
});
|
||||
createEffect(() => {
|
||||
const channelId = payload().guild.channel;
|
||||
setConfig("features", "timePlanning", "channelId", channelId);
|
||||
console.log(channelId, payload());
|
||||
const ref = channelRef();
|
||||
if (!ref) return;
|
||||
if (
|
||||
!ref ||
|
||||
!channelId ||
|
||||
!payload().guild.channels.find((e) => e.id === channelId)
|
||||
)
|
||||
return;
|
||||
ref.value = channelId;
|
||||
});
|
||||
createEffect(() => {
|
||||
const ref = pingableRolesRef();
|
||||
if (!ref) return;
|
||||
ref.checked = config.features.timePlanning.pingableRoles;
|
||||
});
|
||||
createEffect(() => {
|
||||
const ref = timezoneRef();
|
||||
if (!ref) return;
|
||||
|
@ -141,8 +113,6 @@ function config() {
|
|||
ref.checked = config.features.timePlanning.pingableRoles;
|
||||
});
|
||||
|
||||
// console.log(payload());
|
||||
|
||||
return (
|
||||
<Layout site="config">
|
||||
<h3 class="text-center">Configure li'l Judd in</h3>
|
||||
|
@ -232,10 +202,7 @@ function config() {
|
|||
)
|
||||
}
|
||||
>
|
||||
<option
|
||||
disabled={!!config.features.timePlanning.channelId}
|
||||
value=""
|
||||
>
|
||||
<option disabled value="">
|
||||
--Select a Channel--
|
||||
</option>
|
||||
<For each={payload().guild.channels}>
|
||||
|
|
|
@ -3,8 +3,9 @@ import {
|
|||
faCircleExclamation,
|
||||
faPlus,
|
||||
} from "@fortawesome/pro-regular-svg-icons";
|
||||
import { useLocation, useNavigate } from "@solidjs/router";
|
||||
import { For, Suspense, createEffect, createResource } from "solid-js";
|
||||
import { useNavigate } from "@solidjs/router";
|
||||
import { For, createResource } from "solid-js";
|
||||
import { getRequestEvent } from "solid-js/web";
|
||||
import { FontAwesomeIcon } from "~/components/FontAwesomeIcon";
|
||||
import Layout from "~/components/Layout";
|
||||
import "../../styles/pages/config.scss";
|
||||
|
@ -20,38 +21,43 @@ const initialValue = () => ({
|
|||
|
||||
function index() {
|
||||
const navigator = useNavigate();
|
||||
const location = useLocation();
|
||||
const event = getRequestEvent();
|
||||
|
||||
const [payload] = createResource(async () => {
|
||||
const payload = await fetch("http://localhost:3000/api/config")
|
||||
.then(
|
||||
(res) =>
|
||||
res.json() as Promise<
|
||||
| {
|
||||
success: false;
|
||||
message: string;
|
||||
}
|
||||
| (ReturnType<typeof initialValue> & {
|
||||
success: true;
|
||||
})
|
||||
>,
|
||||
)
|
||||
.catch((e) => console.warn(e));
|
||||
const [payload] = createResource(
|
||||
// eslint-disable-next-line solid/reactivity
|
||||
async () => {
|
||||
const payload = await fetch("http://localhost:3000/api/config", {
|
||||
headers: event?.headers,
|
||||
})
|
||||
.then(
|
||||
(res) =>
|
||||
res.json() as Promise<
|
||||
| {
|
||||
success: false;
|
||||
message: string;
|
||||
}
|
||||
| (ReturnType<typeof initialValue> & {
|
||||
success: true;
|
||||
})
|
||||
>,
|
||||
)
|
||||
.catch((e) => console.warn(e));
|
||||
|
||||
if (!payload) return;
|
||||
if (!payload) {
|
||||
console.error("/config", payload);
|
||||
return initialValue();
|
||||
}
|
||||
|
||||
if (!payload.success) {
|
||||
console.log(location.pathname, payload.message, "No success");
|
||||
navigator("/", { replace: false });
|
||||
return initialValue();
|
||||
}
|
||||
console.log(location.pathname, "success");
|
||||
return payload;
|
||||
});
|
||||
createEffect(() => console.log(payload()?.guilds, payload()?.guilds.length));
|
||||
// createRenderEffect(() =>
|
||||
// console.log(payload()?.guilds, payload()?.guilds.length),
|
||||
// );
|
||||
if (!payload.success) {
|
||||
console.log("/config", payload.message, "No success");
|
||||
navigator("/", { replace: false });
|
||||
return initialValue();
|
||||
}
|
||||
|
||||
return payload;
|
||||
},
|
||||
{ deferStream: true },
|
||||
);
|
||||
|
||||
const icons = [faPlus, faCircleExclamation, faBadgeCheck];
|
||||
const colors = [undefined, "orange", "green"];
|
||||
|
@ -60,39 +66,37 @@ function index() {
|
|||
<Layout site="config">
|
||||
<h3 class="text-center">Configure li'l Judd in</h3>
|
||||
<div>
|
||||
<Suspense>
|
||||
<For each={payload()?.guilds}>
|
||||
{(guild, i) => {
|
||||
return (
|
||||
<a
|
||||
href={
|
||||
i() % 3 === 0
|
||||
? `/config/${guild.id}`
|
||||
: `https://discord.com/api/oauth2/authorize?client_id=${import.meta.env.VITE_DISCORD_CLIENT_ID}&permissions=${import.meta.env.VITE_DISCORD_BOT_PERMISSIONS}&scope=bot&guild_id=${guild.id}`
|
||||
<For each={payload()?.guilds}>
|
||||
{(guild, i) => {
|
||||
return (
|
||||
<a
|
||||
href={
|
||||
i() % 3 === 0
|
||||
? `/config/${guild.id}`
|
||||
: `https://discord.com/api/oauth2/authorize?client_id=${import.meta.env.VITE_DISCORD_CLIENT_ID}&permissions=${import.meta.env.VITE_DISCORD_BOT_PERMISSIONS}&scope=bot&guild_id=${guild.id}`
|
||||
}
|
||||
class="flex-row centered"
|
||||
>
|
||||
<img
|
||||
class="guildpfp"
|
||||
src={
|
||||
guild.icon
|
||||
? `https://cdn.discordapp.com/icons/${guild.id}/${guild.icon}.webp?size=240`
|
||||
: "https://cdn.discordapp.com/icons/1040502664506646548/bb5a51c4659cf47bdd942bb11e974da7.webp?size=240"
|
||||
}
|
||||
class="flex-row centered"
|
||||
>
|
||||
<img
|
||||
class="guildpfp"
|
||||
src={
|
||||
guild.icon
|
||||
? `https://cdn.discordapp.com/icons/${guild.id}/${guild.icon}.webp?size=240`
|
||||
: "https://cdn.discordapp.com/icons/1040502664506646548/bb5a51c4659cf47bdd942bb11e974da7.webp?size=240"
|
||||
}
|
||||
alt="Server pfp"
|
||||
/>
|
||||
<h1>{guild.name}</h1>
|
||||
<FontAwesomeIcon
|
||||
// beat={i() % 3 === 1}
|
||||
color={colors[i() % 3]}
|
||||
icon={icons[i() % 3]}
|
||||
size="xl"
|
||||
/>
|
||||
</a>
|
||||
);
|
||||
}}
|
||||
</For>
|
||||
</Suspense>
|
||||
alt="Server pfp"
|
||||
/>
|
||||
<h1>{guild.name}</h1>
|
||||
<FontAwesomeIcon
|
||||
// beat={i() % 3 === 1}
|
||||
color={colors[i() % 3]}
|
||||
icon={icons[i() % 3]}
|
||||
size="xl"
|
||||
/>
|
||||
</a>
|
||||
);
|
||||
}}
|
||||
</For>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue