fix admin redirect loop
This commit is contained in:
@@ -1,11 +1,7 @@
|
|||||||
import { isAdmin } from '~/app/actions'
|
|
||||||
import { redirect } from 'next/navigation'
|
|
||||||
import { servTrpc } from '~/app/_trpc/ServerClient'
|
import { servTrpc } from '~/app/_trpc/ServerClient'
|
||||||
import SystemPromptForm from './_components/SystemPromptForm'
|
import SystemPromptForm from './_components/SystemPromptForm'
|
||||||
|
|
||||||
export default async function SystemPromptPage() {
|
export default async function SystemPromptPage() {
|
||||||
if (!(await isAdmin())) redirect('/admin')
|
|
||||||
|
|
||||||
const prompt = await servTrpc.chat.getSystemPrompt()
|
const prompt = await servTrpc.chat.getSystemPrompt()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { isAdmin } from "~/app/actions";
|
||||||
import { SidebarProvider } from "~/components/ui/sidebar";
|
import { SidebarProvider } from "~/components/ui/sidebar";
|
||||||
import AdminSideBar from "./_components/AdminSideBar";
|
import AdminSideBar from "./_components/AdminSideBar";
|
||||||
import { ScrollArea } from "~/components/ui/scroll-area";
|
import { ScrollArea } from "~/components/ui/scroll-area";
|
||||||
|
|
||||||
export const dynamic = 'force-dynamic';
|
export const dynamic = 'force-dynamic';
|
||||||
|
|
||||||
export default function Admin({children}: Readonly<{children: React.ReactNode}>) {
|
export default async function Admin({children}: Readonly<{children: React.ReactNode}>) {
|
||||||
|
if (!(await isAdmin())) redirect("/");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SidebarProvider>
|
<SidebarProvider>
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
'use server'
|
|
||||||
|
|
||||||
import { Show } from "@clerk/nextjs";
|
|
||||||
|
|
||||||
export default async function AdminPage() {
|
export default async function AdminPage() {
|
||||||
return (
|
return (
|
||||||
<Show when="signed-in">
|
|
||||||
<main className="flex min-h-screen flex-col items-center justify-center">
|
<main className="flex min-h-screen flex-col items-center justify-center">
|
||||||
<div>
|
<div>
|
||||||
hello admin
|
hello admin
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</Show>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/proxy.ts
17
src/proxy.ts
@@ -1,13 +1,16 @@
|
|||||||
import { clerkMiddleware, createRouteMatcher, currentUser } from "@clerk/nextjs/server";
|
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
import { env } from "~/env";
|
import { env } from "~/env";
|
||||||
|
|
||||||
const isTenantAdminRoute = createRouteMatcher(['/admin(.*)'])
|
const isTenantAdminRoute = createRouteMatcher(["/admin(.*)"]);
|
||||||
export default clerkMiddleware(async (auth,req) => {
|
|
||||||
|
export default clerkMiddleware(async (auth, req) => {
|
||||||
if (isTenantAdminRoute(req)) {
|
if (isTenantAdminRoute(req)) {
|
||||||
console.log("running clerk middleware");
|
await auth.protect();
|
||||||
let userid = (await auth()).userId
|
|
||||||
if (userid != env.ADMIN_USER_CLERK_ID) {
|
const { userId } = await auth();
|
||||||
await auth.protect()
|
if (userId !== env.ADMIN_USER_CLERK_ID) {
|
||||||
|
return NextResponse.redirect(new URL("/", req.url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user