The weeb for the next gen discord boat - Wamellow wamellow.com
bot discord
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix /profile & /dashboard auth redirect

Luna 4b831be6 1f3dc107

+26 -18
+5 -5
app/dashboard/[guildId]/layout.tsx
··· 3 3 import { Button, Skeleton } from "@nextui-org/react"; 4 4 import Image from "next/image"; 5 5 import Link from "next/link"; 6 - import { useParams, usePathname } from "next/navigation"; 6 + import { redirect, useParams, usePathname } from "next/navigation"; 7 7 import { useCookies } from "next-client-cookies"; 8 8 import { Suspense, useEffect, useState } from "react"; 9 9 import { HiArrowNarrowLeft, HiChartBar, HiCode, HiCursorClick, HiEye, HiHome, HiShare, HiStar, HiUserAdd, HiUsers, HiViewGridAdd } from "react-icons/hi"; 10 10 11 11 import { guildStore } from "@/common/guilds"; 12 - import { webStore } from "@/common/webstore"; 13 12 import { CopyToClipboardButton } from "@/components/copy-to-clipboard"; 14 13 import ImageReduceMotion from "@/components/image-reduce-motion"; 15 14 import { ListTab } from "@/components/list"; ··· 25 24 children: React.ReactNode 26 25 }) { 27 26 const cookies = useCookies(); 28 - if (cookies.get("hasSession") !== "true") window.location.href = "/login"; 27 + const params = useParams(); 28 + 29 + const authorized = useAuthorize("/dashboard/" + params.guildId); 30 + if (authorized) redirect("/dashboard/" + params.guildI); 29 31 30 32 const guild = guildStore((g) => g); 31 - const web = webStore((w) => w); 32 33 33 34 const [error, setError] = useState<string>(); 34 35 35 - const params = useParams(); 36 36 const path = usePathname(); 37 37 const intl = new Intl.NumberFormat("en", { notation: "standard" }); 38 38
+16 -10
app/login/route.ts
··· 35 35 return Response.json(data); 36 36 } 37 37 38 - // delete didn't work somehow lol 39 38 cookieStore.set( 40 39 "session", 41 - "undefined", 42 - defaultCookieOptions 40 + "", 41 + { 42 + expires: new Date(0), 43 + domain: process.env.NEXT_PUBLIC_BASE_URL?.split("://")[1] 44 + } 43 45 ); 44 46 45 47 cookieStore.set( 46 48 "hasSession", 47 - "false", 49 + "", 48 50 { 49 - ...defaultCookieOptions, 50 - httpOnly: false 51 + expires: new Date(0), 52 + domain: process.env.NEXT_PUBLIC_BASE_URL?.split("://")[1] 51 53 } 52 54 ); 53 55 ··· 58 60 const code = searchParams.get("code"); 59 61 60 62 if (!code) { 61 - redirect(`${process.env.NEXT_PUBLIC_LOGIN}${invite ? "+bot" : ""}`); 63 + const callback = searchParams.get("callback"); 64 + const lastpage = cookieStore.get("lastpage"); 65 + 66 + redirect(`${process.env.NEXT_PUBLIC_LOGIN}${invite ? "+bot" : ""}&state=${encodeURIComponent(callback || lastpage?.value || "/")}`); 62 67 } 63 - 64 - const lastpage = cookieStore.get("lastpage"); 65 68 66 69 const res = await createSession(code, session?.value); 67 70 ··· 86 89 } 87 90 ); 88 91 89 - redirect(lastpage?.value || "/"); 92 + 93 + const state = searchParams.get("state") || "/"; 94 + 95 + redirect(decodeURIComponent(state)); 90 96 91 97 }
+4 -1
app/profile/layout.tsx
··· 3 3 import { Chip, Skeleton } from "@nextui-org/react"; 4 4 import Image from "next/image"; 5 5 import Link from "next/link"; 6 + import { redirect } from "next/navigation"; 6 7 import { useCookies } from "next-client-cookies"; 7 8 import { Suspense } from "react"; 8 9 import CountUp from "react-countup"; ··· 24 25 children: React.ReactNode 25 26 }) { 26 27 const cookies = useCookies(); 27 - if (cookies.get("hasSession") !== "true") window.location.href = "/login"; 28 + const hasSession = cookies.get("hasSession") === "true"; 29 + 30 + if (!hasSession) redirect("/login?callback=/profile"); 28 31 29 32 const user = userStore((u) => u); 30 33 const accent = decimalToRgb(user?.accentColor as number);
-1
lib/api.ts
··· 9 9 export const defaultFetchOptions = { headers: { Authorization: process.env.API_SECRET as string }, next: { revalidate: 60 * 60 } }; 10 10 11 11 export async function getData<T>(path: string, domain?: string) { 12 - console.log(`${domain || process.env.NEXT_PUBLIC_API}${path}`); 13 12 const response = await fetch(`${domain || process.env.NEXT_PUBLIC_API}${path}`, { 14 13 credentials: "include" 15 14 });
+1 -1
utils/authorize-user.ts
··· 3 3 import { User } from "@/common/user"; 4 4 import { RouteErrorResponse } from "@/typings"; 5 5 6 - export default async function authorize({ 6 + export async function authorize({ 7 7 stateHook 8 8 }: { 9 9 stateHook: React.Dispatch<React.SetStateAction<"LOADING" | "ERRORED" | undefined>>;