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 SystemPromptForm from './_components/SystemPromptForm'
|
||||
|
||||
export default async function SystemPromptPage() {
|
||||
if (!(await isAdmin())) redirect('/admin')
|
||||
|
||||
const prompt = await servTrpc.chat.getSystemPrompt()
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { isAdmin } from "~/app/actions";
|
||||
import { SidebarProvider } from "~/components/ui/sidebar";
|
||||
import AdminSideBar from "./_components/AdminSideBar";
|
||||
import { ScrollArea } from "~/components/ui/scroll-area";
|
||||
|
||||
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 (
|
||||
<>
|
||||
<SidebarProvider>
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
'use server'
|
||||
|
||||
import { Show } from "@clerk/nextjs";
|
||||
|
||||
export default async function AdminPage() {
|
||||
return (
|
||||
<Show when="signed-in">
|
||||
<main className="flex min-h-screen flex-col items-center justify-center">
|
||||
<div>
|
||||
hello admin
|
||||
</div>
|
||||
</main>
|
||||
</Show>
|
||||
<main className="flex min-h-screen flex-col items-center justify-center">
|
||||
<div>
|
||||
hello admin
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
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";
|
||||
|
||||
const isTenantAdminRoute = createRouteMatcher(['/admin(.*)'])
|
||||
export default clerkMiddleware(async (auth,req) => {
|
||||
const isTenantAdminRoute = createRouteMatcher(["/admin(.*)"]);
|
||||
|
||||
export default clerkMiddleware(async (auth, req) => {
|
||||
if (isTenantAdminRoute(req)) {
|
||||
console.log("running clerk middleware");
|
||||
let userid = (await auth()).userId
|
||||
if (userid != env.ADMIN_USER_CLERK_ID) {
|
||||
await auth.protect()
|
||||
await auth.protect();
|
||||
|
||||
const { userId } = await auth();
|
||||
if (userId !== env.ADMIN_USER_CLERK_ID) {
|
||||
return NextResponse.redirect(new URL("/", req.url));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user