From d49779e76f445aac36e8ac663b077b636f6e2041 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 2 Jan 2024 17:59:06 +0000 Subject: [PATCH] Fixed settings layout on smaller devices --- app/api/settings/tts/filter/badges/route.ts | 56 --------------------- app/settings/layout.tsx | 4 +- app/settings/page.tsx | 3 -- middleware.ts | 16 ++++-- 4 files changed, 15 insertions(+), 64 deletions(-) delete mode 100644 app/api/settings/tts/filter/badges/route.ts diff --git a/app/api/settings/tts/filter/badges/route.ts b/app/api/settings/tts/filter/badges/route.ts deleted file mode 100644 index 6999c40..0000000 --- a/app/api/settings/tts/filter/badges/route.ts +++ /dev/null @@ -1,56 +0,0 @@ -import axios from "axios" -import { currentUser } from "@/lib/current-user"; -import { db } from "@/lib/db" -import { NextResponse } from "next/server"; - -export async function GET(req: Request) { - try { - const user = await currentUser(); - if (!user) { - return new NextResponse("Unauthorized", { status: 401 }); - } - - let badges = await axios.get("https://api.twitch.tv/helix/chat/badges") - - - const badgesData = await db.ttsBadgeFilter.findMany({ - where: { - data: { - userId: user.id - } - } - }); - - // return NextResponse.json(badgesData); - return new NextResponse("Bad Request", { status: 400 }); - } catch (error) { - console.log("[CONNECTION/TWITCH]", error); - return new NextResponse("Internal Error", { status: 500}); - } -} - -export async function POST(req: Request) { - try { - const user = await currentUser(); - const badges = await req.json(); - - console.log("BADGES", badges); - if (!user) { - return new NextResponse("Unauthorized", { status: 401 }); - } - - // const badgesData = await db.tTSBadgeFilter.createMany({ - // badges.map((badgeName, value) => { - // data: { - // userId: user.id - // } - // }) - // }); - - // return NextResponse.json(badgesData); - return new NextResponse("Bad Request", { status: 400 }); - } catch (error) { - console.log("[CONNECTION/TWITCH]", error); - return new NextResponse("Internal Error", { status: 500}); - } -} \ No newline at end of file diff --git a/app/settings/layout.tsx b/app/settings/layout.tsx index 3b4bb40..3650185 100644 --- a/app/settings/layout.tsx +++ b/app/settings/layout.tsx @@ -10,10 +10,10 @@ const SettingsLayout = async ( return (
-
+
- {header_url}
{children}
diff --git a/app/settings/page.tsx b/app/settings/page.tsx index f52d4f5..577977d 100644 --- a/app/settings/page.tsx +++ b/app/settings/page.tsx @@ -1,9 +1,6 @@ -import { auth } from "@/auth"; - const SettingsPage = async () => { return (
- {JSON.stringify(await auth())}
); } diff --git a/middleware.ts b/middleware.ts index 7ab851d..825ec2b 100644 --- a/middleware.ts +++ b/middleware.ts @@ -7,6 +7,7 @@ import { AUTH_ROUTES, API_PREFIX } from "@/routes" +import { NextResponse } from "next/server" const { auth } = NextAuth(authConfig) @@ -15,26 +16,35 @@ export default auth((req) => { const { nextUrl } = req + // Store current request url in a custom header, which you can read later + const requestHeaders = new Headers(req.headers); + requestHeaders.set('x-url', req.url); + const isApiRoute = nextUrl.pathname.startsWith(API_PREFIX) const isPublicRoute = PUBLIC_ROUTES.includes(nextUrl.pathname) const isAuthRoute = AUTH_ROUTES.includes(nextUrl.pathname) + const response = NextResponse.next({ + request: { + headers: requestHeaders, + } + }); if (isApiRoute) { - return null + return response } if (isAuthRoute) { if (isLoggedIn) { return Response.redirect(new URL(DEFAULT_REDIRECT, nextUrl)) } - return null; + return response; } if (!isLoggedIn && !isPublicRoute) { return Response.redirect(new URL("/auth/login", nextUrl)) } - return null + return response; }) // Optionally, don't invoke Middleware on some paths